Rails 5.xx on Heroku (No routes match [GET] / assets)

I am new to Rails. There was a problem after deploying to Heroku. All assets specified in the controller are not working. Locally everything works fine.

ActionController::RoutingError (No route matches [GET] "/assets/freelancer.min.js"):
ActionController::RoutingError (No route matches [GET] "/assets/portfolio/submarine.png")

      

Example of assets from a controller:

<img src='assets/portfolio/submarine.png' class='img-responsive' alt='Submarine'>

<!-- Theme JavaScript -->
<script src='assets/freelancer.min.js'></script>

      

Does anyone have any idea what is going on?

UPDATE:

thanks for your answer @pythia. This works well with images, but I can't seem to get it to work with java scripts and stylesheets. It looks like Rails cannot find the files, but I checked the JS and CSS and they are present. The code I'm using:

for JS:

<%= javascript_include_tag 'freelancer.min.js'%>

      

for css:

<%= stylesheet_link_tag "bootstrap.min.css", rel: "stylesheet"%>

      

Error log:

ActionController::RoutingError (No route matches [GET] "/javascripts/contact_me.js")
ActionController::RoutingError (No route matches [GET] "/stylesheets/freelancer.min.css")

      

+3


source to share


3 answers


The problem has been resolved. I was describing here here -> Rails Asset Pipeline is not loading my javascript file (why is this code not working

Basically every js file should be included in config / initializers / assets.rb



Example:

Rails.application.config.assets.precompile += %w( freelancer.js )

      

0


source


You need to use helpers like <%= image_tag %>

because the Rails resource pipeline will precompile your images. It will "print" all of your images and add a string of alphanumeric characters to the end of the filename.

So, you need:

<%= image_tag "portfolio/submarine.png", class: "img-responsive", alt: "Submarine"%>

      



If your freelancer.min.js is in the assets / javascripts folder, it is added to your application.js and should be accessible from all over your application.

See the Rails manual for more information on the resource pipeline:

+1


source


You should avoid using HTML tags and use helpers instead:

<%= image_tag 'portfolio/submarine.png', class: 'img-responsive', alt: 'submarine' %>

      

and helper script_tag for script.

0


source







All Articles