开发者

I have a resource named Image in a Rails app. How can I access the dynamically generated path helpers?

The important one in question is MODELNAME_path, which in this case would be image_path, but this seems to clash with the existing method in ActionView::Helpers::AssetTagHelper.

I'm currently calling image_path(@image) in an RSpec view spec file, and it's taking me, reasonably, to the method in AssetTagH开发者_C百科elper and raising an exception, since I'm trying to pass it an object when it ordinarily takes a string.

My first instict was to try url_for, but this, most curiously (and I can't figure out the reason for this one; feel free to enlighten me), eventually just delegates the work back to AssetTagHelper.image_tag. Weird.

So the bottom line question is how I should go about specifically calling the dynamically defined image_tag, and in general how to differentiate the two.

This is the last time I ever name a resource Image.


Have you tried polymorphic_path(@image) instead of image_path(@image) ?


Rails actually recommends you use path_to_image for this exact issue.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜