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.
精彩评论