Image src doesn't look like it's going through asset pipeline - ruby-on-rails

I'm going through the Rails Tutorial by Michael Hartl. In one of the chapters he is explaining about the asset pipeline, and that if I enter the link_to helper code with the image_tag like so:
<%= link_to image_tag("rails.png", alt: "Rails logo"), 'http://rubyonrails.org/' %>
It should see produce something similar to this:
<img alt="Rails logo" src="/assets/rails-9308b8f92fea4c19a3a0d8385b494526.png" />
but in my browser I see the actual image directory
<img alt="Rails logo" src="/assets/rails.png" />
Note the page renders fine in my browser, but I'm wondering why the code doesn't look like it does in the book.

Because you're probably viewing the page in the development environment. The hashed version of the image is created when the assets are compiled. This typically happens when you deploy your app to production.

Related

Rails: get image source after asset precompile

Currently I do this for my website
image_tag("logo.png")
This results
<img src="/assets/logo-c9dc9867ad75fdidmjdoehdo53di.png" alt="Logo" />
This works just fine for me. But sometimes I just need the source part of the image i.e I just need this part /assets/logo-c9dc9867ad75fdidmjdoehdo53di.png. How can I get it?
If your images are in app/assets/images, then use asset_path
<%= asset_path("logo.png") %>
# => "/assets/logo-c9dc9867ad75fdidmjdoehdo53di.png"
If your images are in public/assets, then use image_path
<%= image_path("logo.png") %>
# => "/assets/logo-c9dc9867ad75fdidmjdoehdo53di.png"

Images showing on Heroku with image_tag, but not showing in dev

I have an image that I'm rendering the path with image_tag:
<%= image_tag "piechart.png" %>
...which renders as:
<img src="/images/piechart.png" />
The file resides in app/assets/images/
I can't try to load the image in the browser as it tells me:
No route matches [GET] "/images/piechart.png"
Do I need to edit the routes.rb file for assets? As mentioned, it shows in Heroku (but as /assets/piechart-4f7638b49b22f54811bb6cffc3171810.png)
Thanks

Content for doesn't work in production mode

On one of application's page there is:
<% content_for :head do %>
<%= tag :meta, property: "fb:app_id", content: ENV["FACEBOOK_APP_ID"] %>
<% content_for :title, #check.title %>
<% end %>
And it worked in development, while I was running server at my localhost.
After that I deployed application on heroku. And that simply doesn't work.
What means doesn't work. I load page in development at localhost:
<title>Tenta</title>
<meta content="*****************" property="fb:app_id">
When I load this page deployed at heroku host, these tags are simply absent.
Why?
Also, If you don't know this particular issue solution, I would appreciate if you adivce me, how can I look what is going on - heroku logs and watching last 150 logs in inconvinient windows console doesn't give me a lot of helpful information.

How to the use the image_tag with a remote URL?

I've got a rake task which uploads images I've cached from an API to my S3 bucket. In my view, I try to output the image but it just doesn't appear to work. What I want to do is cache the images onto my filesystem, send them to S3 and I want to use the location of the image from my S3 bucket rather than my filesystem. My code looks like below:
In my rails console, I do this just to check the image url:
1.9.3p125 :002 > a.image
=> http:://s3-eu-west-1.amazonaws.com/ramen-hut/pictures/1.jpg?1343645629
1.9.3p125 :003 >
I use Paperclip in my app, is it supposed to add the url as "http:://"? Seems rather weird. The code in my index.html.erb looks like this:
<li>
<%= movie.title %>
<%= image_tag movie.image.url %>
</li>
But this results in the following html:
<li>
Cowboy Bebop
<img alt="1" src="/assets/http:://s3-eu-west-1.amazonaws.com/ramen-hut/pictures/1.jpg?1343645629">
</li>
Why does it include the '/assets'/ before my URL?
I configured Paperclip to set up the image url for my European S3 Bucket following a tutorial. So in my environment.rb, I've got this:
#Signature correction for Paperclip and AWS
AWS::S3::DEFAULT_HOST = "s3-eu-west-1.amazonaws.com"
And I've got an aws-signature.rb file in my initialisers directory with this code:
#Makes Paperclip use the correct URL for images
Paperclip.interpolates(:s3_eu_url) { |attachment, style|
"#{attachment.s3_protocol}://s3-eu-west-1.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
}
There's a problem with the URL : http::// instead of http:// so image_tag doesn't know it's an absolute URL.
How do you generate these URLs? Gem or your own code?

Is it possible to suppress fingerprinting for image assets used in emails (Rails 3.1)?

In my mailer views, I include images as follows:
<%= image_tag "header.png" , :alt => "" %>
Which results in the following HTML in the generated email
<img alt="" src="http://example.com/assets/header-247cf573710c22ec2c14eafefeb4c7c1.png">
However, in the case of images used in emails, I would prefer NOT to include the fingerprinting. If I change the header image slightly, I would prefer that when a user drags up an old email, they see the new image, rather then getting an error because the old, fingerprinted URL is no longer valid.
In Rails 3.1.1 both versions of assets are available, and you can use the :digest => false option to make Rails give you the plain path to the asset
<image alt="" src="<%= asset_path 'header.png', :digest => false %>" />
You can set this digest for the entire project in your development or production environment config file by adding the below:
# Generate digests for assets URLs
config.assets.digest = false

Resources