One JavaScript per view in Ruby on Rails

0

I am trying not all JavaScripts to be used in all HTMLs.

The first thing I did was eliminate the require_tree.

Then I used this line in my view

<%= javascript_include_tag "fiscal", "data-turbolinks-track" => false %>

and I got this error:

  

Asset was not declared to be precompiled in production.
  Add Rails.application.config.assets.precompile += %w( judicial.js ) to config/initializers/assets.rb and restart your server.

I did what the error says and install something called yarn. Then I ran this code in console:

$ bundle exec rake assets:precompile</code><br>

and I got this:

yarn install v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
info Lockfile not saved, no dependencies.
Done in 0.12s.

But it's still the same error. Please, I need to know where the error is or an alternative.

    
asked by Gabriela Suarez Carvajal 27.12.2017 в 23:21
source

1 answer

0

What you have to do is show you the same error of the screen that you put, add

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

in your file config/initializers/assets.rb and then restart.

Just a separate point, why do not you want to load the same javascript on your pages? In general, the reason this is so is to load a single file when the page loads and therefore make fewer requests to the server of your page. Obviously you can break that rule whenever it is strictly necessary, which most of the time is not.

    
answered by 27.12.2017 в 23:33