我是一个RoR新手(但是经验丰富的开发人员),我一直很享受......但是我已经用Asset Pipeline打了一堵砖墙!我有一个遗留应用程序,我正在修改以使用资产管道。我已经在SO和其他网站上阅读过文章,但我无法让这个工作。以下是详细信息:
Ruby版本:2.0.0-p353
Rails版本:3.1.12
目录 app / assets / javascripts 的内容:
application.js
bootstrap.js
event_calendar.js
jquery-ui-timepicker-addon.js
jquery-ui.js
jquery.js
jquery.prettyPhoto.js
jrails.js
mce_editor.js
rails.js
/tiny_mce
文件 application.js 的内容:
//= require bootstrap
//= require event_calendar
//= require jquery
//= require jquery.prettyPhoto
//= require jquery-ui
//= require jquery-ui-timepicker-addon
//= require jrails
//= require mce_editor
//= require rails
//= require_tree ./tiny_mce
目录 app / assets / stylesheets 的内容:
application.css
/blueprint
bootstrap-responsive.css
bootstrap.css
common.css
contributed.css
event_calendar.css
jquery-custom.css
jquery-ui-timepicker-addon.css
marketing.css
prettyPhoto.css
registration.css
sysadministration.css
template.css
/ui-darkness
文件 application.css 的内容:
/*
*= require bootstrap
*= require bootstrap-responsive
*= require common
*= require contributed
*= require event_calendar
*= require jquery-custom
*= require jquery-ui-timepicker-addon
*= require marketing
*= require prettyPhoto
*= require registration
*= require sysadministration
*= require template
*= require_tree ./blueprint
*= require_tree ./ui-darkness
*/
在 config / application.rb 中设置:
config.assets.enabled = true
app / views / layouts / application.html.erb
中的助手<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
config / environments / development.rb 中的设置:
config.assets.compress = false
config.assets.compile = true
config.assets.debug = true
文件夹 / public / assets 的内容:
(empty)
当我浏览localhost:3000/assets/application.js
时,我只是获取了返回的application.js文件的内容。同样适用于application.css。然而,application.js中有一个显着的尾随分号:
//= require bootstrap
//= require event_calendar
//= require jquery
//= require jquery.prettyPhoto
//= require jquery-ui
//= require jquery-ui-timepicker-addon
//= require jrails
//= require mce_editor
//= require rails
//= require_tree ./tiny_mce
;
我试过追逐那个拖尾的分号而没有运气。我已经改变了require语句的顺序,认为我可能能够缩小.js代码中的任何语法错误,但这种努力是不成功的。
当我的页面被渲染时,它没有任何样式或js(正如预期的那样,因为资产管道不起作用)。
我也尝试在application.css和application.js中使用require_tree .
指令,而不是明确列出每个文件,但这也不起作用。
最后,我的服务器控制台中没有出现任何错误。似乎Rails认为资产得到了正确的服务:
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-08-02 15:31:02 -0400
Served asset /application.css - 304 Not Modified (0ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-08-02 15:31:02 -0400
Served asset /application.js - 304 Not Modified (0ms)
根据我提供的信息,我的配置有任何明显的遗漏吗?任何人都有一些建议让这个工作?
谢谢!
答案 0 :(得分:0)
我决定升级到Rails 3.2.18,这解决了这个问题(我遵循RailsGuides#318“升级到Rails 3.2”)。现在我的js和css正在传送到浏览器:
服务器控制台显示单独交付的资产(开发模式):
Started GET "/assets/bootstrap.css?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /bootstrap.css - 304 Not Modified (0ms)
Started GET "/assets/jquery-custom.css?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /jquery-custom.css - 304 Not Modified (0ms)
Started GET "/assets/contributed.css?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /contributed.css - 304 Not Modified (0ms)
[deleted for brevity]
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /application.css - 304 Not Modified (0ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /jquery.js - 304 Not Modified (0ms)
Started GET "/assets/jquery.prettyPhoto.js?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /jquery.prettyPhoto.js - 304 Not Modified (0ms)
Started GET "/assets/jquery-ui.js?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /jquery-ui.js - 304 Not Modified (0ms)
Started GET "/assets/jquery-ui-timepicker-addon.js?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /jquery-ui-timepicker-addon.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /bootstrap.js - 304 Not Modified (0ms)
Started GET "/assets/event_calendar.js?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /event_calendar.js - 304 Not Modified (0ms)
Started GET "/assets/mce_editor.js?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /mce_editor.js - 304 Not Modified (0ms)
Started GET "/assets/jrails.js?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /jrails.js - 304 Not Modified (0ms)
Started GET "/assets/rails.js?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /rails.js - 304 Not Modified (0ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-08-04 06:07:20 -0400
Served asset /application.js - 304 Not Modified (0ms)