简体   繁体   中英

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 AssetTagHelper 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.

您是否尝试过polymorphic_path(@image)而不是image_path(@image)?

实际上,Rails建议您使用path_to_image解决此确切问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM