Rails Asset Pipeline Not Including Required Files in Application.Js Manifest

Rails asset pipeline not including required files in application.js manifest

I answered this here:

Rails 3.2.8 Application.js and Application.css are not working as expcted

Here's the text:

I was also having this issue but with newer versions of Rails and
Ruby.

Examining the log, I was being served javascript.js from Rails cache
as the server didn't see a change in the file. I went and moved the
require lines around (just one) to tell Rails that there's a change in
the file and re-compile/use. Wellm that did it for me!

Hope it helps somebody.

Another important finding is to upgrade your sprockets gem in your Gemfile.

I had version 2.2.1 and had issues, after upgrading to 2.2.2, it worked

gem 'sprockets', '2.2.2' 

Rails 5 assets not mentioned on the `applications.js` manifest are served?

No, that file is not served by default. By default (depending on Rails version/asset config), only the files listed in Rails.application.config.assets.precompile, by default application.js application.css or in newer Sprockets/Rails via files listed in manifest.js are available for direct serving via javascript_include_tag.

That 2. would raise an error.

Rails Asset Pipeline is not loading my javascript file (why won't this code work

You have probably missed including the file in your manifest file. The manifest file precompiles all the .js files in the assets/javascripts directory into one large file. This is the file that is running on your application. If you do not your .js file there, it is not included and that's why nothing happens.

The right way to include your files is:

//= require mailers.js

in your application.js file. What's more, by default you have

//= require_tree .

which requires all js files from assets/javascript path.

if you want to include it specifically for the view, drop tihs in:

<%= javascript_include_tag "mailers", "data-turbolinks-track" => true  %>

For this, if precompilation is false, you have to add the file separately:
In config/initializers/assets.rb

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

or
In config/application.rb

config.assets.precompile += %w( mailers.js )

The issue might be also that the application precompiles the wrong file if you have a .js and .coffeescript file with the same name. You can try running

   rake assets:clean
rake assets:precompile

And run the server again.

Why are js files in my rails asset pipeline not being compiled?

The problem appears to have been related to my rails/gem versions. After updating from Rails 3.2.8 to Rails 3.2.14 (which also required updating the rack gem from 1.4.1 to 1.4.5) the issue was resolved and items in assets/javascripts are now being compiled/added to public/assets. Note that I created a completely new gemset as part doing this, so the issue may have had nothing to do with the Rails version and simply was a questions of a "corrupted" gem set that needed to be re-created.

Rails asset pipeline doesn't load javascript dependencies

I solved the issue by moving the relevant parts of my main app into a fresh rails app that did load the JS dependencies. I expect this to have been a configuration problem on my side.

More specifically, I moved the Gemfile, db/, config/routes.rb and everything from app/ (except config/) into a fresh rails app. Once everything worked I overwrote my main application's app/ directory with the one from the fresh app.

Rails asset pipeline: Standard way for including all /vendor/assets/javascripts/?

You can add something like this in your app/assets/javascripts/application.js file to include all the vendor javascripts:

//= require_tree ../../../vendor/assets/javascripts/.

How can I include javascript file in the rails assets pipeline?

find: config/initializers/assets.rb
Then: Rails.application.config.assets.precompile += %w[your_file.js]

noticing that as it's out of application.js you need to include it inside your views using:

javascript_include_tag :your_file

Save & Restart your server :)



Related Topics



Leave a reply



Submit