ruby-on-rails - 如何在视图装饰器中连接多个标签
问题描述
我的 Rails 视图中有一个装饰器。
h.content_tag(:p, class:["buttons"]) do
h.mail_to object.email, class:"button is-small" do |button|
h.content_tag(:span, class:["icon","is-small"]) do
"<i class='far fa-envelope'></i>".html_safe
end +
h.content_tag(:span, "Mail")
end
h.link_to admin_participant_path(object), class:"button is-small" do |button|
h.content_tag(:span, class:["icon","is-small"]) do
"<i class='far fa-user'></i>".html_safe
end +
h.content_tag(:span, "Show")
end
end
在我看来,我只渲染了最新的部分,所以基本上是演出。不是电子邮件。如果我添加一个“+”来联系mail_to
和link_to
帮助者,我有一个错误。
我怎样才能连接它们?
解决方案
我认为正确的答案是使用“捕获”和“连接”Rails 助手。
看这篇文章: https ://thepugautomatic.com/2013/06/helpers/
它很旧,但在 Rails 最新版本中应该仍然有效。
推荐阅读
- c++ - 串行通信期间读取的未知字节
- css - 无法在 JavaFX 组合框中自定义文本填充
- c++ - 为什么同一编译器的不同版本会给出不同的结果?
- mongodb - Mongo Collection 名称被截断
- r - 如何生成两列,日期为 2019 年,每个日期的时间段为上午 9 点到晚上 8 点?
- python - 在 scipy.stats 中使用 beta 函数
- c# - 使用 dnSpy 重新编译 DLL - 不可知程序集不能具有特定于处理器的模块 System.EnterpriseServices.Wrapper.dll
- java - 如何在包含的布局中设置 android ImageView 可见性?
- mysql - 字符串搜索查询中的空格导致搜索返回没有结果
- php - 如何使用 php 将数据写入格式化和样式化的 xls 文件(更新数据)