开发者

Using both id and slug when building paths

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜