我是ruby on rails的新手,我在过去3个小时内努力将我的css文件包含在application.scss的vendor / stylesheet /目录中,但它无效。
css文件路径是
vendor/assets/stylesheets/
这是我的代码Application.scss
/*
* 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 any plugin's vendor/assets/stylesheets directory 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 bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*= require custom
*= require pgwmodal.min
*/
这是application.html的代码
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload',debug: true %>
我的项目模式是开发。
我必须重新启动服务器并清除浏览器缓存但仍然没有运气。
答案 0 :(得分:0)
检查您的控制台,看看您的资产是否从任何地方加载。有时您需要将其设为.css.scss
,而不仅仅是.scss
。您通常可以将其保留为.css
。这一切都取决于您的编译器和rails版本。您是否尝试过将其手动放入require_tree .
?
您的自定义.css
需要位于stylesheets文件夹中。如果您尝试从供应商的文件夹加载,您将使用不同的方法。
答案 1 :(得分:-1)
放置css文件的正确路径为vendor/assets/stylesheets/
http://guides.rubyonrails.org/asset_pipeline.html#asset-organization
如果你有
vendor/assets/stylesheets/custom.css
vendor/assets/stylesheets/pgwmodal.min.css
然后您可以加入application.scss
*= require custom.css
*= require pgwmodal.min.css
或者如果将css放在子目录中
vendor/assets/stylesheets/dirname/custom.css
包括使用
*= require dirname/custom.css
您可以在rails中检查加载的路径,输入终端rails c
,然后输入Rails.application.config.assets.paths
以查看资产路径