2015-11-05 99 views
0
controller.rb 

@user = User.where(:id => params[:id]).take 

html.erb 

<a href="/home/layout02_03/<%[email protected]%>"> 
something 
</a> 

點擊該標籤,然後URL是 「/家/ layout02_03/3」如何使用Ruby on Rails的

3用戶的ID隱藏 「ID」 的網址,

但我不」不想揭露說,「ID」

我怎麼能做到這一點,我使用的是軌道

+0

我會改變你的路線。 http://stackoverflow.com/questions/17066637/rails-routes-get-without-param-id –

回答

2

你需要對用戶的模式,如任何其他獨特的屬性紅寶石一些隨機GUID值,一旦你擁有了它,就用它來代替ID:

<a href="/home/layout02_03/<%= @interest.obscure_uniq_identifier %>"> 

或定義它是用戶的默認網址表示:

class User 

def to_param 
    obscure_uniq_identifier 
end 

可以使用生成一個:

before_create :generate_guid 
def generate_guid 
    self.obscure_uniq_identifier = SecureRandom.hex 
end