Home > Mobile >  Why Image_tag produces "images/..." instead of "assets/...."?
Why Image_tag produces "images/..." instead of "assets/...."?

Time:08-01

Rails version: 5.2.4

Ruby version 2.6.10

Per Also the "/assets/..." url can load the image, but "images/..." cannot enter image description here

CodePudding user response:

Because there's a lot of context loaded by Rails for those helper methods to work, you can't just include ActionView::Helpers::AssetTagHelper as you've done. Instead call the helper on the helper object in the rails console:

[1] pry(main)> helper.image_tag("foo.jpg")
=> "<img src=\"/assets/foo-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.jpg\" />"
  • Related