Rails 3.2.8 Application.js 和 Application.css 未按说明工作



当我尝试包含时

<%= stylesheet_link_tag    "application" %>
<%= javascript_include_tag "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 .
*/

并且应用程序.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 文件。但是当我将包含标签更新到特定文件时,这些标签都包含在内。即

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

我认为存在链轮问题,它没有按预期工作,请指教。

我会非常感谢你。

这应该是 ruby 版本问题。您将使用 ruby 2.0.0 ,尝试降级到 1.9.21.9.3 。希望它能奏效。

Nazar Hussain的回答帮助了我。这也取决于红宝石版本。如果您使用的是 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 文件发生了变化并重新编译/使用。好吧,这为我做到了!

希望它对某人有所帮助。

另一个重要发现是升级宝石文件中的链轮宝石。

我有 2.2.1 版并遇到问题,升级到 2.2.2 后,它可以工作

gem 'sprockets', '2.2.2' 

你使用的是 sass 还是更少或类似的东西?

刚刚遇到了这个问题,我发现这是因为应用程序.css文件包含scss代码,默认情况下它无法处理。

只需将文件重命名为 application.css.scss 即可在 Rails 4.2.1 下解决此问题。

最新更新