Ruby on Rails在资源中查找css,而不是public / stylesheets [英] Ruby on Rails looks for css in assets instead of public/stylesheets

查看:64
本文介绍了Ruby on Rails在资源中查找css,而不是public / stylesheets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Ruby新手,使用ruby 1.9.2P180和Rails 3.1.0.rc2



我在my_app_root / public / stylesheets / screen.css和我的application.html.erb

 <%= stylesheet_link_tag'screen.css',:media => ; 'screen'%>根据       >这里应该工作,但我的rails服务器说:


PagesController处理#home作为HTML
呈现的页面/home.html.erb in layouts / application(0.0ms)
完成200 OK在4ms(视图:3.6ms | ActiveRecord:0.0ms)



GET/assets/screen.cssfor 127.0.0.1 at 2011-06-18 11:27:53 +1200
服务资源/screen.css - 404找不到(2ms)(pid 10966)



ActionController :: RoutingError(没有路线与[GET]/assets/screen.css相符):


我在这里做错了什么?



提前感谢

解决方案


我在这里做错了什么?


默认3.1安装,使用新的基于链轮的资产管道。



将您的样式表放入/ app / assets / stylesheets并使用

 <%= stylesheet_link_tag'application.css'%> 

您的观看次数





==



或者,您也可以使用此文件夹中的所有样式表将其自动编译为单个文件。你可以设置在你的application.rb中关闭新的pipline。

  config.assets.enabled = false 


I am new to Ruby, using ruby 1.9.2P180 and Rails 3.1.0.rc2

I have "screen.css" in my_app_root/public/stylesheets/screen.css and in my application.html.erb

 <%= stylesheet_link_tag 'screen.css', :media => 'screen' %>

according to here it should work but my rails server says:

Processing by PagesController#home as HTML Rendered pages/home.html.erb within layouts/application (0.0ms) Completed 200 OK in 4ms (Views: 3.6ms | ActiveRecord: 0.0ms)

Started GET "/assets/screen.css" for 127.0.0.1 at 2011-06-18 11:27:53 +1200 Served asset /screen.css - 404 Not Found (2ms) (pid 10966)

ActionController::RoutingError (No route matches [GET] "/assets/screen.css"):

What am I doing wrong here?

Thanks in advance

解决方案

What am I doing wrong here?

Nothing, you are just using a default 3.1 install which uses the new sprockets-based asset pipeline.

put your stylesheets into /app/assets/stylesheets and use

<%= stylesheet_link_tag 'application.css' %> 

in your views

the new pipeline takes all the stylesheets in that folder and automagically compiles them into a single file.

==

Alternatively, you can set turn the new pipline off in your application.rb with

config.assets.enabled = false

这篇关于Ruby on Rails在资源中查找css,而不是public / stylesheets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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