2013-06-04 4 views
-1

레일 앱에 대한 이메일 입력 라우팅의 이름을 바꾸려고합니다. 현재 누군가가 이메일을 입력하면/: controller/: id로 라우팅합니다. 일단 이메일을 입력하면 ID를 표시하지 않으므로 ID 번호를 변경하거나 다른 사람의 이메일을 볼 수 없습니다. 이메일.레일 이름 바꾸기 레일

+0

"누군가가 자신의 이메일을 입력 할 때"-> 입력? 그것을 제한하기 위해 단순히'before_filter'를 추가하지 않는 것이 어떻습니까? – kiddorails

답변

0

편집 : 난 내 자신을 시도하고 있었다이 그 이메일의 경우 작품을 dosn't,하지만 당신은 특별한 carracters와 사용자 이름을하려고하면 그것이 잘 작동합니다

! 이 같은

시도 뭔가 :

경로 :

match "/controller/:username" => "controller#show" 

컨트롤러 :

def show 
    @user = find_by_username(params[:username]) 
end 
+0

나는 그것을 시도했지만 이메일을 입력 할 때/emailinputs /로 라우팅된다. : id –

0

나는 생각한다, 서로 보안 이메일을주고 몇 가지 숫자와 고유 주소를 사용합니다. 왜냐하면 당신은 사람들 모델을 가지고 있다고 가정합니다.

당신은, people에 하나 개의 속성을 추가 할 필요가 이름 people.rb

rails g migration add_permalink_to_peoples permalink:string 
rake db:migrate 

을 실행하려고 permalink

이다 속성, before_save

class People < ActiveRecord::Base 
    attr_accessible :email, :permalink 
    before_save :make_it_permalink 

def make_it_permalink 
    # this can create permalink with random 8 digit alphanumeric 
    self.permalink = SecureRandom.base64(8) 
end 

end 

그리고 당신의 routes.rb

플레이
match "/people/:permalink" => 'peoples#show', :as => "show_people" 

및 실행 rails server

def show 
    @people = People.find_by_permalink(params[:permalink]) 
end 

peoples_controller.rb에하는 일명를 추가합니다.

사람들은 임의의 8 자리 숫자와 독특한 고유 주소를 (예를 들어, /people/:permalink)

예 : http://localhost:3000/people/9sd98asj