I want to do some Facebook posting from an observer class, however, I want to reference an image from my server. In the past I have had some pretty hackie methods of doing this, but now with the new assets stuff, I though I could use image_path or image_url methods.
However, I can't seem to figure out how to call these. They are not class level methods of ActionView::Helpers::AssetTagHelper so doing
ActionView::Helpers::AssetTagHelper.image_url
Doesn't work.
First of all, I don't think image_url
exists. I only see image_path
in the API.
To be able to use that method, you have to include the AssetTagHelper module:
include ActionView::Helpers::AssetTagHelper
image_path('my_image.png')
In Rails 4 include AssetUrlHelper:
include ActionView::Helpers::AssetUrlHelper
image_path('my_image.png')
In Rails 4 we can use image_url
with host
attribute.
As @piotrkaczmarek mentioned above we need to include AssetUrlHelper.
include ActionView::Helpers::AssetUrlHelper
image_url('image.jpg', host: 'http://example.com')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With