Rails 3.2.8 Application.js and Application.css are

2019-02-06 10:40发布

问题:

When i try to include

<%= stylesheet_link_tag    "application" %>
<%= javascript_include_tag "application" %>

The content of the files of the application.css is:

/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require social_stream
*= require_tree .
*/

And the content of application.js file is

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require social_stream-base
//= require social_stream-documents
//= require social_stream-events
//= require social_stream-linkser
//= require social_stream-presence
//= require social_stream-oauth2_server
//= require_tree .

my rails app is not including the css and js files those are required in the above snippet. but when i update the include tags to the specific file those are included fine. i.e.

<%= stylesheet_link_tag    "social_stream" %>
<%= javascript_include_tag "jquery" %>

What i think there is issue of sprockets its not working as expected please advice.

I will be really thankful to you.

回答1:

It should be ruby version issue. You would be using ruby 2.0.0, try to downgrade to 1.9.2 or 1.9.3. Hope it will work.



回答2:

Nazar Hussain's answer helped me. It depends on ruby version too. If you are using v.2 then try to downgrade to v.1.9. It is very easy if you are using rvm:

To install v.1.9.3 use:

$ rvm install 1.9.3

To use v.1.9.3 as default:

$ rvm --default use 1.9.3

Then

  • restart your terminal
  • install bundler gem
  • run bundle install
  • run rake assets:clean RAILS_ENV=development
  • start your server rails s

That's all.



回答3:

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' 


回答4:

Are you using sass or less or something similar?

I just had this problem and I found it was because the application.css file contained scss code, which it cannot handle by default.

Simply renaming the file to application.css.scss resolved this issue under Rails 4.2.1.