插入ruby代码打破html

时间:2013-12-19 10:54:57

标签: html ruby-on-rails ruby

我的代码使用check方法返回true或false

<%= link_to path, format: 'js' do %>
            <i class="<%= check ? "close\"></i>Unfollow member" : "open\"></i>Follow member></i>" %>
<% end %>
</div>
  <div class="list-group list-normal m-b-none">

但输出

<i class="close&quot;&gt;&lt;/i&gt;Unfollow member
&lt;/a&gt;  &lt;/div&gt;
  &lt;div class=" list-group="" list-normal="" m-b-none"="">
</i>

怎么可能? (我不想重复check标签内外的i声明)

2 个答案:

答案 0 :(得分:1)

我认为以下内容会更具可读性:

<% if check %>
  <i class="close">Unfollow member</i>
<% else %>
  <i class="open">Follow member></i>
<% end %>

更新:

使它成为一个班轮:

<%= check ? "<i class='close'>Unfollow member</i>" : "<i class='open'>Follow member></i>" %>

答案 1 :(得分:0)

<%= link_to path, format: 'js' do %>
  <i class="<%= check ? "'close'></i>Unfollow member" : "'open'></i>Follow member>" %></i>
<% end %>

我没试过。但是如果可行的话。