ruby-on-rails - 如何为rails中的布局设置特定样式
问题描述
我需要特定布局的特定样式表。
例如index.html.erb
需要特定的样式表。
为什么需要这个,因为任何布局都有不同的主体样式。
当加载index.html.erb
加载时custom.css.scss
解决方案
在您的布局文件中,假设application.html.erb
文件:
使用条件样式表:如果是PostController
和'index,则加载custom.css.scss ,否则加载custom2.css.scss
编辑:加载除custom.css.scss
. 然后使用条件语句custom.css
仅在PostController
'index
方法中加载
<%= stylesheet_link_tag 'style1' %>
<%= stylesheet_link_tag 'style2' %>
<%= stylesheet_link_tag 'style3' %>
<% if params[:controller] == 'post' && params[:action] == 'index' %>
<%= stylesheet_link_tag 'custom' %>
<% end %>
推荐阅读
- bash - 从 shell 脚本中读取命令行参数
- c++ - 在使用 nlohmann::json 时使用 std::eof 读取 json 文件
- node.js - Node.js - 检查特定的 CharSet
- modelica - 在作用域 _ 中找不到函数 _
- python-3.x - Python3 Web-scraping无法登录页面?时间戳?
- python - 如何保存由内置身份验证实现的用户表单中的数据。用户在 Django 中使用 UserCreationForm?
- javascript - VideoJS v7.7.6 - player.qualityLevels() 不适用于 VHS
- c# - C# NullChecking: a is null vs object.Equals(a, null)
- java - 无法将字符串解析为 Java 8 LocalDateTime
- c# - C# Automapper 内部列表来自另一个不同类型的内部列表