I have a rails 3.x application that has model classes which return content to a view partial to be rendered on a page. The model takes care of what the content is and just returns it to the view which blindly adds it to the page. In other words, the view calls the model asking for its content; the model delivers its content HTML-Safe to the view; and the view just dumps what is returned into into its output.
Thus far, everything works.
I need to make such a class that returns the html for a link to an image in the asset pipeline (the view does not know or care that the thing being returned is an image).
In it's simplest form, the model reads a record from the database which contains a filename, "my_image.png". It needs to return to the view the HTML referring to the image with that name that is located in "app/assets/images".
Is it possible to do this ?
This will work inside Model
ActionController::Base.helpers.image_tag("image.png")
try including helper in model include ActionView::Helpers
& ActionView::Helpers::AssetTagHelper
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