image_path returns a path only (no host).
The url_for helper won't accept a single path, so something like url_for(image_path('image.png')) wouldn't work. While the internal url_for in ActionDispatch::Http::Url.url_for would appear to do the trick (source), there doesn't seem to be a public interface for it.
How should I go about doing it? Ultimately, it'd be nice to have a function like image_url that works like url_for does for routes so that I could call image_url('image.png') and get the absolute URL given all of the default_url_options.
You should use request. original_url to get the current URL.
The lib/assets (or sometimes vendor/assets ) is where you supposed to place js/css/images related to your front-end design and provided by third party libs. Say if you want to pull in some css or a js framework, that were you should place it.
def image_url(source) URI.join(root_url, image_path(source)) end This way you get url either using assets_host or joining with root_url.
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