生产中的Rails错误,可能是由于link_tag和预编译

Sat*_*har 4 deployment ruby-on-rails ruby-on-rails-3

我已经安装rails 3.1apache2passengerubuntu 10.04.使用ruby 1.9.2RVM.当我在生产中的浏览器中加载应用程序(开发版本在我的机器上工作正常)时,它不起作用.

我的生产错误日志是:

Started GET "/articles" for 117.230.75.50 at 2011-09-12 13:51:34 +0000
Processing by ArticlesController#index as HTML
Rendered articles/index.html.erb within layouts/application (56.4ms)
Completed 500 Internal Server Error in 126ms

ActionView::Template::Error (application.css isn't precompiled):
    2: <html>
    3: <head>
    4:   <title>Youexpress</title>
    5:   <%= stylesheet_link_tag    "application" %>
    6:   <%= javascript_include_tag "application" %>
    7:   <%= csrf_meta_tags %>
    8: </head>
  app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__385712067674585148_29380260'
  app/controllers/articles_controller.rb:7:in `index'
Run Code Online (Sandbox Code Playgroud)

但是,当我像这样删除app/views/layouts/application.html.erb中的link_tags时,应用程序在生产模式下工作正常.

<!DOCTYPE html>
<html>
<head>
  <title>Youexpress</title>
</head>
<body>

<%= yield %>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?当我这样做时,bundle exec rake assets:precompile我收到以下错误:

rake aborted!
no such file to load -- uglifier
  (in /home/username/youexpress/vendor/bundle/ruby/1.9.1/gems/jquery-rails-1.0.14/vendor/assets/javascripts/jquery-ui.min.js)
Run Code Online (Sandbox Code Playgroud)

注意:在上面的错误中它显示ruby/1.9.1而不是1.9.2(我已经安装了1.9.2)

请帮助我的情况.

谢谢

Sat*_*har 6

我自己找到了答案,错误的原因是rails app需要javascript运行时sass,coffeescript和uglifier的某些功能才能工作.

通过安装javascript运行时,有很多方法可以解决这个问题 nodejs

但是,我采用的解决方案,也许是最简单的解决方案,添加gem 'therubyracer'到我的Gemfile然后运行bundle install

我的摘录Gemfile如下

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'therubyracer'
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end
Run Code Online (Sandbox Code Playgroud)

添加therubyracer修复程序rake assets:precompile

希望这可以帮助.我花了几天时间寻找这个解决方案.