通过了一些解决方案,并在我的development.rb
文件
config.assets.precompile = true
config.assets.precompile = ['*.js', '*.css', '*.css.erb']
仍面临同样的问题。有人可以帮忙吗?
以下是application.css
文件
/*
*= require_tree .
*= require_self
*/
我正在尝试加载内容为
的register.html.erb
中的css
<h1>Register#register</h1>
<p>Find me in app/views/register/register.html.erb</p>
我尝试加载的样式表是style_pub.css
h1 {
color : green;
}
控制台日志错误:
Started GET "/stylesheets/assets/stylesheets/application.css" for ::1 at 2016-08-06 17:17:43 +0530
ActionController::RoutingError (No route matches [GET] "/stylesheets/assets/stylesheets/application.css"):
actionpack (4.2.5.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.5.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.5.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.5.1) lib/rails/rack/logger.rb:20
application.html.erb
档案:
<!DOCTYPE html>
<html>
<head>
<title>CssTest</title>
<%= stylesheet_link_tag 'assets/stylesheets/application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'assets/javascripts/application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
建议更改后的新错误日志:
Started GET "/register/register" for ::1 at 2016-08-06 17:46:41 +0530
Processing by RegisterController#register as HTML
Rendered register/register.html.erb within layouts/application (0.0ms)
Completed 500 Internal Server Error in 384ms (ActiveRecord: 0.0ms)
ActionView::Template::Error (TypeError: Object doesn't support this property or method):
2: <html>
3: <head>
4: <title>CssTest</title>
5: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6: <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7: <%= csrf_meta_tags %>
8: </head>
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___978862768_58522776'
答案 0 :(得分:0)
将您的css
文件从public
目录移至app/assets/stylesheets/
目录,它将解决您的问题。
*= require_tree .
中的application.css
代码行包含css
目录中的所有app/assets/stylesheets/
个文件。
替换下面的行 从
<%= stylesheet_link_tag 'assets/stylesheets/application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'assets/javascripts/application', 'data-turbolinks-track' => true %>
到
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
它会正常工作
答案 1 :(得分:0)
这一定对您有用
请将样式表添加到app / assets / stylesheet文件夹中的application.css文件。
/*
*= require style_pub
*= require_tree .
*= require_self
*/
现在尝试重新启动服务器,如果仍然无法正常工作。