【问题标题】:Rails link_to with complex HTML inside带有复杂 HTML 的 Rails link_to
【发布时间】:2015-06-21 13:13:12
【问题描述】:

我正在尝试使用 link_to 对以下代码块进行编码

<a class="item-over" href="host.html">
                  <div class="item-time"> <span class="item-month">Jun</span> <span class="item-date">30</span> </div>
                  <div class="item-attending">
                    <div class="item-attending-content"> <span class="user-number">2</span> <span class="user-text">attending</span> </div>
                  </div>
                </a>

在上面我想从数据库数据中替换以下文本

六月

30

2

我的代码:

<%= link_to '<div class="item-time"> <span class="item-month">Jun</span> <span class="item-date">30</span> </div><div class="item-attending"><div class="item-attending-content"> <span class="user-number">2</span> <span class="user-text">attending</span> </div></div>'.html_safe, event_path(fevent), {:class => 'item-over'} %>

我无法在区块中添加#{}

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 hyperlink


    【解决方案1】:
    <%= link_to event_path(fevent), {:class => 'item-over'} do %>
    Your HTML here
    <% end %>
    

    【讨论】:

      【解决方案2】:

      您希望能够在字符串中使用#{}?然后你需要在字符串周围使用双引号"而不是单引号'

      【讨论】:

        【解决方案3】:

        这看起来很适合link_to 的块形式。

        <%= link_to event_path(fevent), class: "item-over" do %>
          # complex HTML
        <% end %>
        

        【讨论】:

          猜你喜欢
          • 2012-11-09
          • 1970-01-01
          • 2013-07-22
          • 2011-07-20
          • 1970-01-01
          • 2023-04-04
          • 2017-09-23
          • 2012-04-03
          • 1970-01-01
          相关资源
          最近更新 更多