I have a model, let's say user, with bo开发者_运维知识库th an id and a slug. I'd like to be able to generate a url using user_path(@user) that contains both the id and slug.
I know that user_path will use to_param method for the parameter it puts at the end of the url, but is there a way to use 2 (or more parameters) and get something like this: http://domain.com/users/id/slug
Thanks!
Friendly-id is a great way to generate permalinks. It also offers pretty good customization options.
Did you try this in your model?
def to_param
"#{id}-#{slug)"
end
精彩评论