Rails 3.2.8 Application.js和Application.css不能正常工作
当我试图包括
application.css的文件内容是:
/* * 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 . */
而application.js文件的内容是
// 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 .
我的rails应用程序不包括上述代码段中所需的css和js文件。 但是当我将包含标签更新到特定文件时,这些包含在内。 即
我认为有链轮的问题,它没有按预期工作,请建议。
我真的很感谢你。
它应该是ruby版本问题。 您将使用ruby 2.0.0
,尝试降级到1.9.2
或1.9.3
。 希望它会奏效。
Nazar Hussain的回答帮助了我。 这也取决于ruby版本。 如果您使用的是v.2,请尝试降级到v.1.9。 如果你使用rvm很容易:
要安装v.1.9.3,请使用:
$ rvm install 1.9.3
要将v.1.9.3用作默认值:
$ rvm --default use 1.9.3
然后
- 重启你的终端
- 安装
bundler
gem - 运行
bundle install
- 运行
rake assets:clean RAILS_ENV=development
- 启动你的服务器
rails s
就这样。
我也有这个问题,但有更新版本的Rails和Ruby。
检查日志时,我正在从Rails缓存中获取javascript.js,因为服务器没有看到文件中的更改。 我去了并移动了需求线(只有一个)告诉Rails文件有变化并重新编译/使用。 Wellm为我做了!
希望它对某人有帮助。
另一个重要发现是升级Gemfile中的sprockets gem。
我有2.2.1版本并且有问题,在升级到2.2.2之后,它有效
gem 'sprockets', '2.2.2'
你使用sass或更少或类似的东西?
我刚遇到这个问题,我发现这是因为application.css文件包含scss代码,默认情况下无法处理。
只需将文件重命名为application.css.scss即可解决Rails 4.2.1下的这个问题。