生产中的Rails错误可能是由于link_tag和预编译 [英] Rails Error In Production, may due to link_tag and precompilation

查看:79
本文介绍了生产中的Rails错误可能是由于link_tag和预编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将 rails 3.1 apache2 乘客 ubuntu 10.04 。使用 ruby​​ 1.9.2 RVM
当我在生产中的浏览器中加载应用程序(开发版本在我的机器上正常工作)时,它不起作用。



我的生产错误日志是: / p>

 开始获取/ articles为117.230.75.50在2011-09-12 13:51:34 +0000 
处理ArticleController#index作为HTML
在布局/应用程序中呈现的文章/ index.html.erb(56.5ms)
在126ms内完成500内部服务器错误

ActionView :: Template :: Error(application.css未预编译):
2:< html>
3:< head>
4:< title> Youexpress< / title>
5:<%= stylesheet_link_tag应用程序%>
6:<%= javascript_include_tagapplication%>
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'

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

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

<%= yield%>

< / body>
< / html>

我该如何解决?当我执行 bundle exec rake assets:precompile 我收到以下错误:

 耙子中止! 
没有这样的文件加载 - uglifier
(在/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应用程序需要javascript运行时的某些功能的sass ,coffeescript和uglifier工作。



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

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



摘自我的 Gemfile

 #宝石仅用于资产在生产环境中,d不需要
#。
group:assets do
gem'therubyracer'
gem'sass-rails',〜> 3.1.0
gem'coffee-rails',〜> 3.1.0
gem'uglifier'
end

添加 therubyracer 还修复耙资产:预编译



希望这有帮助。我花了几天时间搜索这个解决方案。


I have installed rails 3.1 with apache2 and passenger on ubuntu 10.04. using ruby 1.9.2 with RVM. When I load the application in browser in production (development version works fine on my machine), it does not work.

My Production Error Log is:

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'

But, when I remove the link_tags in app/views/layouts/application.html.erb like this, the application works fine in production mode.

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

<%= yield %>

</body>
</html>

How do I get Around this? When I do bundle exec rake assets:precompile I get the following error:

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)

Note: In the above error it shows ruby/1.9.1 not 1.9.2 ( I've installed 1.9.2 )

Please help with my situation.

Thanks

解决方案

I've found the answer myself, The reason for the error is rails app needs javascript runtime for certain features of sass, coffeescript and uglifier to work.

There are many ways to solve this, by installing javascript runtimes like nodejs

But, the solution I went with, and perhaps the easiest one is, adding gem 'therubyracer' to my Gemfile and then running bundle install

Excerpt from my Gemfile is below

# 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

adding therubyracer also fixes rake assets:precompile

Hope this helps. I've spent days searching for this solution.

这篇关于生产中的Rails错误可能是由于link_tag和预编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆