开发者

Is there a way to get Rails to guess a resource's #edit path the same way it does with the #show path?

In Rails, you can do link_to "text", resource or url_for resource and Rails will try to guess the path to the resource from the resource's class and id. Is there any way to do the same by for the edit link?

I could probably have something together to just append "/edit" the the #show path, but that doesn't seem very pleasant.

Side question: is there 开发者_开发问答a way to get the collection path for a model given the model class?


link_to 'Edit This Thing', [:edit, @thing] # = edit_thing_path(@thing)
link_to 'Things Index', Thing # = things_path

These call polymorphic_path under the hood, as you already mentioned.


I found polymorphic_path, which seems to do the trick. You call it in this fashion:

polymorphic_path([:edit, resource])


I think this is what you're looking for:

link_to "text", edit_resource_path(resource)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜