Ruby on Rails:如何使用 rails 项目添加 css 文件? [英] Ruby on Rails: How can I add a css file with rails project?

查看:29
本文介绍了Ruby on Rails:如何使用 rails 项目添加 css 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

application.html.erb 文件:

The application.html.erb file:

<!DOCTYPE html>
<html>
<head>
  <title>Site</title>
  <%= stylesheet_link_tag    :all %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>

我在 public/文件夹中有一个文件cake.generic.css".

I have a file "cake.generic.css" in public/ folder.

但是当我重新加载页面时,css文件的效果不起作用.

But when I reload the page the effect of css file is not working.

如果我看到页面视图源,我会看到如下内容:

If I see the page view source I see something like this:

<!DOCTYPE html>
<html>
<head>
  <title>Site</title>
  <link href="/assets/all.css" media="screen" rel="stylesheet" type="text/css" />
  <script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/home.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>

  <meta content="authenticity_token" name="csrf-param" />
<meta content="6CPvchXr1amagxd7VmOzB82WGx/WmjfDOXjMLfjLzqQ=" name="csrf-token" />
</head>
<body>

<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>


</body>
</html>

我应该怎么做才能解决这个问题?

What should I do to fix this problem?

如何为样式表和 javascript 设置公共文件夹?

How can I set the public folder for stylesheets and javascripts?

看起来 app/assets 文件夹是为 css 和 js 文件设置的?

It looks that app/assets folder is set for css and js files?

推荐答案

Rails 很可能将您所有的 css 文件整合到一个它称为 assets/all.css 的文件中

Rails is likely consolidating all your css files into one that it is calling assets/all.css

考虑使用免费插件 firebug + firepath 以进一步描述问题.这种常见的工具组合将帮助您查询网页元素并查看有助于其显示的 css.

Consider using the free plug-ins firebug + firepath to further characterize the problem. This common combo of tools will help you to interrogate web page elements and see the css that is contributing to their display.

这篇关于Ruby on Rails:如何使用 rails 项目添加 css 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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