向样式表添加新样式不能在导轨中工作 [英] Adding new styles to stylesheet not working in rails

查看:161
本文介绍了向样式表添加新样式不能在导轨中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ROR应用程式。它在其 public / scaffold_files 文件夹中有一个 style.css 样式表。当我检查元素时,我可以看到这个文件的样式引用。但现在我想改变/添加一些样式。我对此文件所做的任何更改不会在视图中受到影响。 我们如何添加新样式我不想使用< style> 标记并在视图中编写代码,我想要在样式表中。
PS:这个 style.css 文件在布局文件中引用如下,我可以看到

I'm working on a ROR app. It has a style.css stylesheet in its public/scaffold_files folder. I can see the style reference to this file when I inspect the elements. But now I want to change/add some styles. Any changes I make to this file is not affected in the view. How do we add new styles?? I dont want to use the <style> tag and write code in the view itself, I want it in a stylesheet. PS: this style.css file is referred in the layout file as below and I can see the same when I do 'view page source'.

  <link href="/scaffold_files/style.css" rel="stylesheet" type="text/css" media="all">


推荐答案

rails asset pipeline分为3个不同的部分。

The rails asset pipeline is broken up into 3 different sections.


  • 应用程式/资产适用于应用程式拥有的资产,通常由您自己撰写。

  • app/assets is for assets that are owned by the application, usually scripted by yourself.

lib / assets适用于您自己的库代码,它不适合在应用程序的范围内使用

或共享
的库

lib/assets is for your own libraries' code that doesn't really fit
into the scope of the application or those libraries which are shared across applications.

供应商/资产适用于第三方资源,例如js外挂程式和框架。

vendor/assets is for assets that are 3rd party, such as js plugins and frameworks.

在公用文件夹中开始添加资产通常是不好的做法。当您的资产管道尝试在生产环境中编译和压缩它们时,它将无法找到它们,因为它只在应用程序,lib和供应商文件夹中。

It is generally bad practise to start adding assets in the public folder. When your asset pipeline tries to compile and compress them in production, it won't be able to find them because it only looks in the app, lib and vendor folders.

要开始,只需在app / assets文件夹中创建一个名为application.css的文件。然后使用以下语法在布局(layout / application.html.erb)中引用此文件:

To get started, just create a file called 'application.css' within the app/assets folder. Then reference this file within your layout (layout/application.html.erb) using the following syntax:

<%= stylesheet_link_tag :application %>

这将自动查找app / assets文件夹,并检索名为application的文件。从而在您的应用程序中呈现新样式!

This will automatically look in the app/assets folder, and retrieve, the file named 'application'. Thereby rendering new styles within your applcation!

如果您需要有关资产的进一步帮助,请查看RailsGuides;他们有很多有用和深入的内容。

If you need further help with assets, check out the RailsGuides; they have alot of helpful and in depth content.

http://guides.rubyonrails.org/asset_pipeline.html

这篇关于向样式表添加新样式不能在导轨中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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