当我从3.1.1 Rails升级到3.2.8时,看到样式表,图像的路由错误真的很令人沮丧。尝试了“捆绑exec rails服务器”命令,并尝试逐个添加文件中的宝石,也不起作用:(
ActionController::RoutingError (No route matches [GET] "/stylesheets/application.css"):
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.8) 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.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/application.rb:223:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
答案 0 :(得分:1)
在链接到rails中的资源时,请始终使用asset_path
,asset_url
或其中一个依次调用这些函数的辅助函数(image_path
,image_url
,{{ 1}},javascript_include_tag
)。
在您的情况下,您似乎在应用程序布局中硬编码stylesheet_link_tag
。简单地将代码改为
/stylesheets/application.css
它应正确指向<%= stylesheet_link_tag :application %>
进行开发,并/assets/application.css
进行生产(编译资产时)。
此外,如果你有本地编译的资产(如果/assets/application-<sha1 hash>.css
中有任何内容,则情况如此。如果您在本地开发,可能需要public/assets
),那么您需要以下内容rm -rf public/assets
中的一行:
config/application.rb