简体   繁体   中英

inserting ruby code breaks html

I have this code with a check method that returns true or 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">

but this outputs

<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>

How can it be ? (I don't want to repeat the check statement inside and outside the i tag)

I think following will be more readable:

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

Update:

To make it one liner:

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

I did not try. But if may works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM