Reputation: 13
controller.rb
@user = User.where(:id => params[:id]).take
html.erb
<a href="/home/layout02_03/<%[email protected]%>">
something
</a>
click that a tag then url is "/home/layout02_03/3"
3 is user's id,
but I don't want to expose that "id"
how can I do that, I'm using ruby on rails
Upvotes: 0
Views: 1470
Reputation: 324
For anyone who is having the same issue, I would also suggest you to use a gem like Visibilize which offers more options on creating exposable friendly ID's.
Just install the gem and call visibilize
inside your model.
Upvotes: 0
Reputation: 6132
You need to have any other unique attribute on the User model, e.g. some random GUID value, once you have it, just use it instead of the ID:
<a href="/home/layout02_03/<%= @interest.obscure_uniq_identifier %>">
Or define it to be the default URL representation for the User:
class User
def to_param
obscure_uniq_identifier
end
You can generate one using:
before_create :generate_guid
def generate_guid
self.obscure_uniq_identifier = SecureRandom.hex
end
Upvotes: 2