首页 > 解决方案 > CSS 使用 Rails 自动链接到 HTML

问题描述

我在 app/assets/stylesheets 中为我的 Ruby on Rails 项目创建了一个 style.css 文件。我添加了一些样式并启动了服务器。我没有在任何 html.erb 文件中放置任何<link href...>或任何位置,但每个页面都有我在 style.css 中编写的 css 更改stylesheet_link_tag

此外,我现在必须在每次更改 CSS 时重新启动服务器才能在浏览器中看到这些更改。有没有人遇到过这个?顺便说一句,我正在使用动作电缆。我也没有 public/assets 文件夹。

应用程序.js

require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")

require("jquery")
$(document).on('turbolinks:load', function () {
    alert("Hello!");
})

应用程序.css

/*
 * 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, 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_tree .
 *= require_self
 */

样式.css

table{
    border-collapse: collapse;
}

table, th, td{
    border: 1px solid black;
}

#left, #right {float:left}
#left {width: 30%;}
#right {width: 70%;}

标签: ruby-on-rails

解决方案


推荐阅读