Andrey
Andrey

Reputation: 63

Rails 5.x.x on Heroku (No route matches [GET] /assets)

I´m new to Rails. Having an issue after deploying to Heroku. All the assets that are indicated in the controller are not working. Locally all works fine.

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

Assets example from the controller:

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

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

Does anyone have an idea what is happening?

UPDATE:

Thx for your response @pythia. This worked well with images, but I can't make it work with java scripts and style sheets. It looks like Rails can't find the files, but I've checked JS and CSS and they are present. The code that I'm using is:

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")

Upvotes: 3

Views: 1331

Answers (3)

Andrey
Andrey

Reputation: 63

Problem solved. I did everithing described here -> Rails Asset Pipeline is not loading my javascript file (why won't this code work

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

Example:

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

Upvotes: 0

pythia
pythia

Reputation: 13

You need to use helpers like <%= image_tag %> because the Rails' asset pipeline precompiles your images. It'll "fingerprint" each of your images and add a string of alphanumeric characters to the end of the filename.

So you'll want:

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

If your freelancer.min.js is in the assets/javascripts folder, it gets added to your application.js and should be available from throughout your app.

There's more info in the Rails guide to the asset pipeline:

Upvotes: 1

tildedash
tildedash

Reputation: 71

You must avoid using HTML tags and use helpers instead :

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

and the script_tag helper for the script.

Upvotes: 0

Related Questions