开发者

Rails 3.0 Frontend URL's with slugs, backend URL's without

开发者 https://www.devze.com 2023-03-03 09:56 出处:网络
Is there any way to use the slugs generat开发者_如何学运维ed by overriding \"to_param\" in the model for only the frontend?

Is there any way to use the slugs generat开发者_如何学运维ed by overriding "to_param" in the model for only the frontend?

Eg, In my model I have:

def to_param
  "#{id}-#{name.parameterize}"
end

And it works great on the frontend. But the problem seems to be, on the backend adminstrative side, you can edit the name/title. This ends up with a bunch of weird stuff when I start editing things.

Is there any easy way to simply use the #{id} only if I'm in the namespaced admin backend?


Please check the gem Friendly_ID. It deals with slugs in a very nice way.

If the name changes (which is your identifier for the edited object), the id does not change. So when you edit or update an object, you could use the id for identification, rather than the slug.

0

精彩评论

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