2015-11-05 45 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