Get fullpath from paperclip - ruby-on-rails

I have paperclip, but its url method returns only the path not the full url. I want to construct the full url from that paperclip. Beside doing string concatenation, is there a better way to create full url from a image path string like "/images/11/1.jpg"?
E.g. Given the string "/images/11/1.jpg", I want to get "http://www.example.com/images/11/1.jpg"
Additionally, I want to switch the subdomain to 'assets'.

You can try to use environment variables in paperclip...
Using the Rails Enviroment URL in a MODEL with paperclip
but i don't know if it still works

Related

How can I save part of URL using Katalon?

I would like to save part of the URL and I don't really know how to do it. I would like to save the part of the URL in a variable.
Anyone has an idea how to do it?
First, to get the current url, use
current_url = WebUI.getUrl()
Then you will need to use some kind of string manipulations to get the part that you need.
Katalon uses Groovy language, so you can read about the string methods here.
For example, if current_url='https://www.tutorialspoint.com/groovy/groovy_strings.htm' you wish to get only the part of the url after the last / try something like this:
split_url = current_url.split('/')
partial_url = split_url[split_url.size()-1]
println partial_url
The result of the above is "groovy_strings.htm".

What is the purpose of using rails' image_url helper?

From the docs it seems like you just save yourself from typing in the assets folder part of the image url when using this method against the vanilla url helper? What is the usefulness of this?
When you use image_url helper then rails will map the full qualified url based on the asset_host configuration. So this method gives you the freedom of just passing the name of the image as an argument and it does the rest.
Check this for more information.
http://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html

Get ASP.NET bundle URL for use with CDN?

I'm using the ASP.NET bundling feature and want to know how I can get the URL returned by the Render helpers such as Scripts.Render("~/bundles/scripts").
Currently the optimized output is has a relative URL. I want to use a CDN that does origin-caching, so the final URL needs to be something like http://static.mydomain.com/bundles/scripts?v=XXXXXX
My plan is to simply write my own helper method, but I can't figure out how to get the version number relative URL for a given bundle.
The solution was rather simple. There is a static method Scripts.Url and Styles.Url that give me exactly what I want. I was able to incorporate this into my own helper to concatenate the CDN's base URL.

Paperclip Rails url and asset_host

According to the Paperclip S3 Docs one can specify the :url option in the config which has four possible values. There are comments related to this options that say:
The fourth option for the S3 url is :asset_host, which uses Rails' built-in asset_host settings.
To get the full url from a paperclip'd object, use the image_path helper; this is what image_tag uses to generate the url for an img tag.
These two comments seem in conflict with each other (to me). If Paperclip can use the asset_host settings, it seems almost necessary that it would generate the full url (since the asset_host only specifies the start (host) of that url)
But it then goes on to say you need to use a helper to get the full url??
The reason I ask this is because I want full urls generated for image url serialization (ie if we're returning json with image_urls, we want those served from our CDN).
Right now I've created a helper module that extends extend ::Sprockets::Helpers::RailsHelper to manually generate full urls any time an image_url is being serialized, but it's manual (and someone could possibly forget to do it in the future)
Any thoughts?

Access public files in Rails

I want to access the file /public/images/dog.jpg in the Rails project. Is there some URL route that would access it?
I tried public/images/dog.jpg and images/dog.jpg, but it didn't work.
images/dog.jpg is correct.
However I would use the image_path URL route, e.g. image_path('dog.jpg').
See http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

Resources