Rails Rails 3.2.1 生产环境下出问题了

metal · 2012年02月16日 · 最后由 string2020 回复于 2015年06月10日 · 6467 次阅读
Started GET "/posts/new" for 127.0.0.1 at 2012-02-16 10:56:27 +0800
Processing by PostsController#new as HTML
  Rendered posts/_form.html.erb (6.0ms)
  Rendered posts/new.html.erb within layouts/application (7.0ms)
Completed 200 OK in 10ms (Views: 10.0ms)


Started GET "/stylesheets/bootstrap.css" for 127.0.0.1 at 2012-02-16 10:56:27 +0800

ActionController::RoutingError (No route matches [GET] "/stylesheets/bootstrap.css"):
  actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  rack-cache (1.1) lib/rack/cache/context.rb:132:in `forward'
  rack-cache (1.1) lib/rack/cache/context.rb:241:in `fetch'
  rack-cache (1.1) lib/rack/cache/context.rb:181:in `lookup'
  rack-cache (1.1) lib/rack/cache/context.rb:65:in `call!'
  rack-cache (1.1) lib/rack/cache/context.rb:50:in `call'
  railties (3.2.1) lib/rails/engine.rb:479:in `call'
  railties (3.2.1) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

我已经执行了rake assets:precompile并且生成好了。只是生成的路径有问题,html 代码里的样式表指向的是stylesheets目录,生成的确在assets目录,还老是提示GET /favicon.ico这个错误。= =

<link href="/stylesheets/bootstrap.css" media="all" rel="stylesheet" type="text/css" />
<script src="/javascripts/application.js" type="text/javascript"></script>

很奇怪。生成环境下的生成的样式和 js 应该后面还带一写字符串的才对。

你的和是手写上去的吧! <p>你有在用 <code>stylesheets_link_tag</code> 和 <code>javascript_include_tag</code> 吗?</p> <div class="highlight"><pre class="highlight erb"><code><span class="cp">&lt;%=</span> <span class="n">stylesheets_link_tag</span><span class="p">(</span><span class="s2">"bootstrap"</span><span class="p">)</span> <span class="cp">%&gt;</span> <span class="cp">&lt;%=</span> <span class="n">javascript_include_tag</span><span class="p">(</span><span class="s2">"application"</span><span class="p">)</span> <span class="cp">%&gt;</span> </code></pre></div> <p>BTW. Rails 3.1 以后,CSS,JS 已经到 <code>/assets/</code> 目录下面了。</p>

#1 楼 @huacnlee 我是这样的写的。

<%= stylesheet_link_tag("bootstrap-min") %>
<%= javascript_include_tag("application") %>

很奇特

ActionController::RoutingError (No route matches [GET] "/favicon.ico"):
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'

提示 GET /favicon.ico 你 google 下 favicon.ico 就晓得是啥子了

好吧。我搞定了。太坑爹了~~~

能说下你是怎么解决的吗?我正被 rake assets:precompile 困扰呢

production asset pipline 的路径问题: 参考: config/environments/production.rb中

Disable Rails's static asset server (Apache or nginx will already do this)

config.serve_static_assets = true

默认是 false,如果用 rails s -e production,请改成 true。

place favicon.ico in public folder

#4 楼 @metal 我也遇到了这个问题,请问是怎么解决的呢? #6 楼 @23c 如果用 nginx 就不需要改config.serve_static_assets吧?

楼主是怎么解决的。 我已经把 favicon.ico 放到 public 目录里面了,但是,还是报这个错误

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