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

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

我的生产错误日志是:

 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:  3:  4: Youexpress 5:  6:  7:  8:  app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__385712067674585148_29380260' app/controllers/articles_controller.rb:7:in `index' 

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

    Youexpress      

我该如何解决这个问题? 当我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) 

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

请帮助我的情况。

谢谢

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

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

但是,我使用的解决方案,也许最简单的解决方案是,在我的Gemfile添加gem 'therubyracer' ,然后运行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 

添加therubyracer还修复了rake assets:precompile

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