新手问题 deploy rails4 with nginx and passenger need run "bundle exec rake assets:precompile"?

yehualiu · 2014年04月19日 · 最后由 yehualiu 回复于 2014年04月21日 · 6194 次阅读

Like the title.thanks.

#1 楼 @Rei so the /opt/nginx/conf/nginx.conf must setting like this ??

server {
    listen       80;
    server_name  you.host.name; # 请替换成你网站的域名
    rails_env    production;
    root         /home/jason/www/gitlab/public;
    passenger_enabled on;

    location ~ ^(/assets) {   #The important
      access_log        off;
      expires           max; 
    }
  }

but my zurb-foundation template can't work correct.

if i don't add this:

location ~ ^(/assets) {   #The important
      access_log        off;
      expires           max; 
    }

my zurb-foundation template can't work correct.

#4 楼 @yehualiu What error. (log)

ActionController::RoutingError (No route matches [GET] "/assets/foundation-wysihtml5/index.css"):

I, [2014-04-19T16:23:24.666455 #3727] INFO -- : Started GET "/assets/foundation-icons.ttf" for 50.117.115.237 at 2014-04-19 16:23:24 +0800 F, [2014-04-19T16:23:24.667543 #3727] FATAL -- : ActionController::RoutingError (No route matches [GET] "/assets/foundation-icons.ttf"): actionpack (4.0.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in call' actionpack (4.0.3) lib/action_dispatch/middleware/show_exceptions.rb:30:incall' railties (4.0.3) lib/rails/rack/logger.rb:38:in call_app' railties (4.0.3) lib/rails/rack/logger.rb:20:inblock in call' activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in block in tagged' activesupport (4.0.3) lib/active_support/tagged_logging.rb:25:intagged' activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in tagged' railties (4.0.3) lib/rails/rack/logger.rb:20:incall' actionpack (4.0.3) lib/action_dispatch/middleware/request_id.rb:21:in call' rack (1.5.2) lib/rack/methodoverride.rb:21:incall' rack (1.5.2) lib/rack/runtime.rb:17:in call' activesupport (4.0.3) lib/active_support/cache/strategy/local_cache.rb:83:incall' rack (1.5.2) lib/rack/sendfile.rb:112:in call' railties (4.0.3) lib/rails/engine.rb:511:incall' railties (4.0.3) lib/rails/application.rb:97:in call' passenger (4.0.41) lib/phusion_passenger/rack/thread_handler_extension.rb:74:inprocess_request' passenger (4.0.41) lib/phusion_passenger/request_handler/thread_handler.rb:141:in accept_and_process_next_request' passenger (4.0.41) lib/phusion_passenger/request_handler/thread_handler.rb:109:inmain_loop'

#4 楼 @yehualiu How you link css assets in layout?

This block means cache this files under /assets, in general it will not cause error. So how do you deploy?

#6 楼 @yehualiu How you link foundation-wysihtml5/index.css, does you require it in application.css or append it to precomple target?

#11 楼 @yehualiu What is yes mean?

thanks, I do it myself

@Rei

#3 楼 What error -> What's the error

#8 楼 How you link css assets in layout? -> How do you link css assets in layout?

#9 楼 does you -> do you

一个技术过关的工程师不应该在这些地方犯错误,没恶意,不过我觉得既然用了英文,写对这些就很重要。

你当然需要 bundle exec rake assets:precompile 没有恶意,我认为你用中文或许能更准确描述你的问题

Rails3 也要啊,除非你 serve_static_assets=true

thanks .我先自已解决,再没搞定,再向大牛求助 #17 楼 @SharpX #16 楼 @huacnlee #15 楼 @Rei

#14 楼 @willmouse @Rei 我觉得意思到了就行,人脑模糊识别和纠错能力是少数比电脑强的地方之一,不利用起来多可惜 :D

#12 楼 @Rei #16 楼 @huacnlee

不好意思,还是没有解决,谢谢了哈

#20 楼 @yehualiu 这个只是有属性无效的警告,不是错误。

#21 楼 @Rei 但在 development 下,可以的嘛

在 prodution 环境下,页面就无法正常显示了

#20 楼 @yehualiu 从这个图看,也只有 logo.png 是 404 的,其他都正常啊,jscss 都打包好了。

#23 楼 @yehualiu 那么你看看 production 下是什么错误。

#20 楼 @yehualiu 你需要确定一下,哪一部分 cssjs 导致的页面不正常,才好根据根据具体情况分析

#26 楼 @lonre #25 楼 @Rei

I, [2014-04-20T12:37:47.916557 #4993]  INFO -- : Started GET "/" for 127.0.0.1 at 2014-04-20 12:37:47 +0800
I, [2014-04-20T12:37:48.166054 #4993]  INFO -- : Processing by StaticPagesController#home as HTML
I, [2014-04-20T12:37:48.310119 #4993]  INFO -- :   Rendered static_pages/home.html.haml within layouts/application (11.9ms)
I, [2014-04-20T12:37:48.370456 #4993]  INFO -- :   Rendered layouts/_seo.html.haml (15.6ms)
I, [2014-04-20T12:37:48.384051 #4993]  INFO -- :   Rendered layouts/_shim.html.haml (3.9ms)
I, [2014-04-20T12:37:48.387417 #4993]  INFO -- :   Rendered layouts/_head.html.haml (59.3ms)
I, [2014-04-20T12:37:48.613887 #4993]  INFO -- :   Rendered layouts/_navbar.html.haml (218.1ms)
I, [2014-04-20T12:37:48.823821 #4993]  INFO -- :   Rendered layouts/_footer.html.haml (204.2ms)
I, [2014-04-20T12:37:48.825427 #4993]  INFO -- : Completed 200 OK in 655ms (Views: 491.5ms | ActiveRecord: 41.9ms)
I, [2014-04-20T12:37:49.000870 #4993]  INFO -- : Started GET "/default/logo.png" for 127.0.0.1 at 2014-04-20 12:37:49 +0800
F, [2014-04-20T12:37:49.005858 #4993] FATAL -- : 
ActionController::RoutingError (No route matches [GET] "/default/logo.png"):
  actionpack (4.0.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.3) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.3) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.3) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.3) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.0.3) lib/rails/engine.rb:511:in `call'
  railties (4.0.3) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /home/kevin/.rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /home/kevin/.rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /home/kevin/.rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'


I, [2014-04-20T12:37:49.807919 #4993]  INFO -- : Started GET "/default/logo.png" for 127.0.0.1 at 2014-04-20 12:37:49 +0800
F, [2014-04-20T12:37:49.812687 #4993] FATAL -- : 
ActionController::RoutingError (No route matches [GET] "/default/logo.png"):
  actionpack (4.0.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.3) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.3) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.3) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.3) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.0.3) lib/rails/engine.rb:511:in `call'
  railties (4.0.3) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /home/kevin/.rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /home/kevin/.rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /home/kevin/.rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'


日志显示 public 目录下没有 /default/logo.png 这个文件。我想不至于导致样式不正常吧。

其实到现在我都不知道楼主想做什么,发生了什么错误。

主要是 zurb foundation 的一些样式,无法正常显示 #28 楼 @Rei

#28 楼 @Rei 比如 Orbit 样式显示不出来,还有下拉菜单显示不出来,等等,完全影响了页面的部局和显示效果,就如 20 楼 我发的截图一样,这些效果显示不出来,但在 development 下能显示,而到了 production 就不显示了了

#29 楼 @yehualiu 那么你要有针对性的查看 zurb foundation 的文件有没有载入:

  1. 打开浏览器调试,看看对应的 css 或其他静态文件有没有载入
  2. 检查 public/assets 下面有没有正确生成静态文件

#31 楼 @Rei 显示都正常的,只是在浏览器上显示 这些借误

#32 楼 @yehualiu 那么你觉得错误的样式是什么,调试看看它的 css 是什么,有没有对应样式。

#29 楼 @yehualiu 如何使用 zurb foundation 的?

#34 楼 @lonre gem 'foundation-rails', '5.1.1.0' gem 'will_paginate', '~> 3.0.4' gem 'foundation-will_paginate' gem 'foundation-icons-sass-rails' gem 'foundation-wysihtml5-rails'

#35 楼 @yehualiu 看你最终打包的 css 文件也就一个 application.css 了,你大概看看 zurb foundation 的样式被打包了么?

#37 楼 @yehualiu 这是啥,不是最终打包的 application-87967d.....css 吧?

application-b90139c1a32eb4597ba8d4f8c801ba37.css 的前面一部分代码是:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the top of the
 * compiled file, but it's generally better to create a new file per style scope.
 *





 */
meta.foundation-version {
  font-family: "/5.1.0/"; }

meta.foundation-mq-small {
  font-family: "/only screen and (max-width: 40em)/";
  width: 0em; }

meta.foundation-mq-medium {
  font-family: "/only screen and (min-width:40.063em)/";
  width: 40.063em; }

meta.foundation-mq-large {
  font-family: "/only screen and (min-width:64.063em)/";
  width: 64.063em; }

meta.foundation-mq-xlarge {
  font-family: "/only screen and (min-width:90.063em)/";
  width: 90.063em; }

meta.foundation-mq-xxlarge {
  font-family: "/only screen and (min-width:120.063em)/";
  width: 120.063em; }

meta.foundation-data-attribute-namespace {
  font-family: false; }

html, body {
  height: 100%; }

*,
*:before,
*:after {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box; }

html,
body {
  font-size: 100%; }

body {
  background: white;
  color: #222222;
  padding: 0;
  margin: 0;
  font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  position: relative;
  cursor: default; }

a:hover {
  cursor: pointer; }

img,
object,
embed {
  max-width: 100%;
  height: auto; }

#38 楼 @lonre

#39 楼 @yehualiu 这段代码你格式化了?

现在你需要确定的是:production 环境下,确定 zurb foundation 相关的 css 有没有打包到最终的 application-......css 中。如果application-......css不包含 zurb foundation 相关的 css 代码,那么就是引入的问题;如果包含了相关的代码,那么还要进一步确定导致你页面异常的那部分代码是什么,再进一步查看问题,一点一点细化吧。

#38 楼 @lonre 在 development 下都显示正常,但是经过 assets compile 后,就不正常了

#40 楼 @lonre 这代码我没有格式化,打开 sublime text 就这样了

#41 楼 @yehualiu 嗯,一般单独引入文件的时候会出现这样的情况。

我建议你还是做一个最简单的能重现问题的应用,给大家看一下,这样大家可以快速的帮你定位问题,解决问题。

#43 楼 @lonre

一般单独引入文件的时候会出现这样的情况。

一般是怎么解决的呢?

#44 楼 @yehualiu 你这种情况,我估计不是这个原因,因为你使用了 gem 包。

类似这种 http://ruby-china.org/topics/18667

#45 楼 @lonre 我都是用的 gem 包,在 development 下正常,就是不知道怎么回事的

#46 楼 @yehualiu 我建议你做个简单的应用,重现一下问题。这样描述起来太费劲了。

#47 楼 @lonre @Rei

又出现这个问题了

movie git:(master) ✗ RAILS_ENV=production bundle exec rake assets:precompile --trace ** Invoke assets:precompile (first_time) ** Invoke assets:environment (first_time) ** Execute assets:environment ** Invoke environment (first_time) ** Execute environment ** Execute assets:precompile rake aborted! Unexpected character '#' (line: 25970, col: 0, pos: 815789)

Error at new JS_Parse_Error (/tmp/execjs20140420-13049-1d1u7ss.js:2357:10748) at js_error (/tmp/execjs20140420-13049-1d1u7ss.js:2357:10967) at parse_error (/tmp/execjs20140420-13049-1d1u7ss.js:2357:12685) at Object.next_token as input at next (/tmp/execjs20140420-13049-1d1u7ss.js:2357:19006) at semicolon (/tmp/execjs20140420-13049-1d1u7ss.js:2357:19851) at simple_statement (/tmp/execjs20140420-13049-1d1u7ss.js:2357:22663) at /tmp/execjs20140420-13049-1d1u7ss.js:2357:20814 at /tmp/execjs20140420-13049-1d1u7ss.js:2357:20063 at /tmp/execjs20140420-13049-1d1u7ss.js:2358:40 at Object.parse (/tmp/execjs20140420-13049-1d1u7ss.js:2358:249)

#48 楼 @yehualiu 把代码 push 到 github。

#49 楼 @Rei #47 楼 @lonre

问题解决了哈,谢谢了

#50 楼 @yehualiu 是什么问题,并且怎么解决的呢?

是 js 文件里面有单独一行揄入了#符号

#52 楼 @yehualiu

Unexpected character '#' (line: 25970, col: 0, pos: 815789)

是这一行吧,你这 js 真是超长啊

需要 登录 后方可回复, 如果你还没有账号请 注册新账号