Rails 3.1 absolute URL to an image
See the Using asset hosts section in the documentation. You need to specify an asset_host
. You can also construct it dynamically from the request chaining "#{request.protocol}#{request.host_with_port}"
How do I get an absolute URL for an asset in Rails 3.1?
It would appear that as of recently, sass-rails
now interprets the image_url
command within a scss file in the expected manner, resolving to the final location of the image in question.
Full url for an image-path in Rails 3
try path
method
Image.find(:first).image.path
UPD
request.host + Image.find(:first).image.url
and you can wrap it as a helper to DRY it forever
request.protocol + request.host_with_port + Image.find(:first).image.url
How do I get full URL to an image in a Rails asynchronous mailer?
Well this is odd behaviour, but I've resolved this issue. It turns out that unless the action_mailer.asset_host starts with http://
then it will be ignored. There is a Regex in actionpack/lib/action_view/helpers/asset_url_helper.rb
that defines a valid ActionMailer URI:
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}
However, if you put a http://
in front of the action_controller.asset_host
then you will end up with links to http://http://myfullappurl.dev
So to resolve it I had to add the following to my development.rb
config.action_controller.asset_host = 'myfullappurl.dev'
config.action_mailer.asset_host = 'http://myfullappurl.dev'
Just to be clear, this is Rails 4.0.0beta1 with the emails being sent asynchronously with Sidekiq, I am not sure if this affects Rails 3.
Get Full URL for ActiveStorage image
I'm not sure if this is the recommended way, but you can use the polymorphic_url helper:
polymorphic_url object.image.variant(resize: '140x140')
How to have asset_path return an absolute URL?
Use asset_url
<meta property="og:image" content="<%=asset_url('logo_400x200.jpg') %>" />
Generate absolute URL from an array of route components
You can simply use url_for:
link_to 'My account', url_for([:edit, :admin, :account, :details])
Check out this document
Related Topics
How to Make a Post Request with Open-Uri
How to Robustly Parse Malformed CSV
How to Disable Db:Schema:Dump for Migrations
Creating Permutations from a Multi-Dimensional Array in Ruby
Zlib in Ruby to Uncompress .Gz
How to Customize the Table Builder Plugin for a Week Calendar
How to Remove the String "\N" from Within a Ruby String
Generating an Instagram- or Youtube-Like Unguessable String Id in Ruby/Activerecord
Elasticsearch & Tire: Using Mapping and To_Indexed_JSON
Xpath Expression for Regex-Like Matching
Assign/Replace Params Hash in Rails
Jekyll Serve Dependency Error - Could Not Open 'Lib Curl'