Rails 3.1资产预编译

时间:2011-12-13 20:59:15

标签: ruby-on-rails apache2 capistrano

我正在开发rails 3应用程序并尝试在生产环境中部署它。 我正在使用capistrano来部署我的应用程序并将其配置为在update_code任务之后预编译资产。

当我部署应用程序时,一切正常。 通过遵循服务器生产日志,我看到了:

Compiled application.js  (6ms)  (pid 7552)
Compiled jquery.js  (4ms)  (pid 7552)
Compiled jquery_ujs.js  (0ms)  (pid 7552)
Compiled home.js  (94ms)  (pid 7552)
Compiled libs/dd_belatedpng.js  (0ms)  (pid 7552)
Compiled libs/modernizr-1.7.min.js  (0ms)  (pid 7552)
Compiled plugins.js  (0ms)  (pid 7552)
Compiled script.js  (0ms)  (pid 7552)
Compiled user_sessions.js  (93ms)  (pid 7552)
Compiled users.js  (92ms)  (pid 7552)
Compiled application.css  (3ms)  (pid 7552)
Compiled handheld.css  (0ms)  (pid 7552)
Compiled home.css  (55ms)  (pid 7552)
Compiled style.css  (0ms)  (pid 7552)
Compiled user_sessions.css  (1ms)  (pid 7552) 
Compiled users.css  (0ms)  (pid 7552)
Compiled application.js  (6ms)  (pid 7541)
Compiled jquery.js  (4ms)  (pid 7541)
Compiled jquery_ujs.js  (0ms)  (pid 7541)
Compiled home.js  (95ms)  (pid 7541)
Compiled libs/dd_belatedpng.js  (0ms)  (pid 7541)
Compiled libs/modernizr-1.7.min.js  (0ms)  (pid 7541)
Compiled plugins.js  (0ms)  (pid 7541)
Compiled script.js  (0ms)  (pid 7541)
Compiled user_sessions.js  (93ms)  (pid 7541)
Compiled users.js  (94ms)  (pid 7541)
Compiled application.css  (2ms)  (pid 7541)
Compiled handheld.css  (0ms)  (pid 7541)
Compiled home.css  (1ms)  (pid 7541)
Compiled style.css  (0ms)  (pid 7541)
Compiled user_sessions.css  (0ms)  (pid 7541)
Compiled users.css  (0ms)  (pid 7541)

但是如果我尝试在浏览器中显示主页面,我就明白了:

ActionView::Template::Error (style.css isn't precompiled):
    14: 
    15:     %link{:rel => "shortcut icon", :href => "/favicon.ico" }
    16:     %link{:rel => "apple-touch-icon", :href => "/apple-touch-icon.png"}
    17:     = stylesheet_link_tag    "style"
    18:     = javascript_include_tag "libs/modernizr-1.7.min"
    19:     = javascript_include_tag "application"
    20: 
  app/views/layouts/application.html.haml:17:in         `_app_views_layouts_application_html_haml__1713356285_69878424198520'

我只是无法理解服务器如何能够告诉我资产是否已编译,并且在它告诉我实际上文件未编译之后。

有没有人遇到过这种问题?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

一种解决方案是告诉生产环境不要在config/environments/production.rb中检查预编译并设置行:

config.assets.compile = false

config.assets.compile = true

重新启动您的服务器,然后您应该检查HALM寻找style.css的{​​{1}}

的位置

更新

这是另一个选择

告诉你的assets/style.css编译那个确切的文件以确保它正在被编译。

config/environments/production.rb

https://stackoverflow.com/a/7541958/295228

上看到了这个