Rails: Why images are not showing in my rails basic app
If you are using asset pipeline http://guides.rubyonrails.org/asset_pipeline.html,
The image path should be /assets/product1.jpg
instead of /images/product1.jpg
If you are not using asset pipeline, move the images folder to public/images
Why are images not showing in Rails app deployed on Heroku?
After searching I stumbled upon a solution , but do not know why it worked.
bundle exec rake assets:precompile
worked and made the images appear.
I had previously tried
bundle exec rake assets:precompile RAILS_ENV=production
This solved my problem, but I am at a loss as to whether the command bundle exec rake assets:precompile RAILS_ENV=production
did not also solve the problem as I assume that it is doing the same thing as far as Heroku is concerned. The other confusing thing is that the html output remains the same as stated above in the original question. including the differences even though the pages look identical with images included.
If anyone could comment as to why this solution worked it could improve the answer for others with the same issue and also help me understand what went wrong.
Ruby on Rails - Images not displaying
you don't need to include 'assets/' in the path:
<%= image_tag '7apps.jpg' %>
as for the products loop this should be enough, although i have no idea what image_url
contains:
<%= image_tag product.image_url, class: 'list_image' %>
why are images not showing in my rails app?
for problem 1, because your website's css is empty, nothing in. The css link is https://cherry-cupcake-30790.herokuapp.com/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css .
for problem 2, the image link refer is not in the html, but in the css file.
#mainpic {
background-image: url(images/main.jpg);
background-repeat: no-repeat;
width: 900px;
height: 354px;
}
the image link is http://www.quackit.com/html/templates/download/bryantsmith/greenmountain/images/main.jpg
Image not loading in dynamic page of Ruby on Rails app
If the image tag has the following exact image path specified:
<img src="assets/m1.jpg" etc="etc">
...then the browser will treat that as a relative URL and try to look it up relative to the URL of the current page, which is http://localhost:3000/posts/2
.
As a result, the browser will look for an image with this URL: http://localhost:3000/posts/assets/m1.jpg
, which is exactly what's happening in your case.
Try using the image_tag
helper instead:
<%= image_tag "m1.jpg" %>
Related Topics
Resetting a Singleton Instance in Ruby
What Is the Community-Preferred Ruby Unit Testing Framework
Rails/Rspec: How to Test #Initialize Method
<Rubygems> How to Change Gem Environment Settings
Rails: Switch Connection on Each Request But Keep a Connection Pool
How to Find Where a Ruby Method Is Declared
Rails Can't Login to Postgresql - Pg::Error - Password - Correct Info
How to Authorize a Google Service Account Without the Default Credentials File
Find Memory Leak in a Ruby on Rails Project
Using Ruby, Reading a File, Containing Name/Value Pairs into a Hash
Stylesheet_Link_Tag :All Versus :Media =>All
Adding Keywords to Ruby Syntax Highlighting for Notepad++
Active Admin Scopes for Each Instance of a Related Model
Can't Convert Symbol into String
Running Multiple Background Parallel Jobs with Rails
Using Ruby and Net-Ssh, How to Authenticate Using the Key_Data Parameter with Net::Ssh.Start