ruby-on-rails - 使用 Ruby on Rails 将链接的字体颜色设置为变量
问题描述
如何将链接的字体颜色设置为内联特定变量的值?我可以将其设置为特定颜色,如下所示。
<%= link_to "Click for more information", info_url(@site), style: 'color: #cc0000;' , class: 'button' %>
将变量插入颜色选择器的语法是什么?我没想到下面的代码可以工作,但这就是我想做的事情的本质。
<%= link_to "Click for more information", info_url(@site), style: 'color: @site.colour' , class: 'button' %>
解决方案
你想要的是字符串插值 http://ruby-for-beginners.rubymonstas.org/bonus/string_interpolation.html
IE:
<%= link_to "Click for more information", info_url(@site), style: "color: #{@site.colour}" , class: 'button' %>
推荐阅读
- php - MAMP PRO 6 命令行快捷方式不起作用
- javascript - 将 Jquery 滚动更改为页面加载
- python - 找不到记录器“azure.storage.common.storageclient”的处理程序 - 尝试从 raspi4 将图像上传到 azure 存储
- c# - 如果未覆盖游戏对象,则 Unity2d 手柄单击
- c++ - 除非我添加额外的“cout”行,否则 C++ 代码长整数函数不能正常工作?
- ios - 关闭应用程序并断开与 Wi-Fi 的连接后,Parse 不会将对象保存在本地数据存储中
- c++ - 允许用户输入更改函数参数 C++
- python - TTK 组合框样式不正确
- c# - SignalR 与服务器的连接问题
- javascript - MongoDB 连接到 Robo 3T 但数据不显示