6

I've rewritten my html code with rails content_tags and now I want to add if-statements to them.

Before I had:

<% if ... %>
    <div class='...'>
    ...
    </div>
<% end %>

Now I have 2 types of this block:

<%= content_tag(:div, ..., class: 'some_class') if ... %>

This works ok. But when I try to add if-statement to do-end block it fails:

<%= content_tag(:div, class: 'some_class') if ... do %>
    ...
<% end %>

I'm seeing this, instead of div content:

<div>{:class=>"some_class"}</div>

Thanks!

4

2 回答 2

16

你必须像这样使用:

<%if ... %>
    <%= content_tag(:div, class: 'some_class') do %>
    ...
    <% end %>
<% end %>

或者在块之后使用 if 语句:

<%= content_tag(:div, class: 'some_class') do %>
    ...
<% end if .......%>
于 2013-06-24T05:26:13.200 回答
4

尝试

<%= content_tag(:div, class: 'some_class')  do %>
    ...
<% end if ... %>
于 2013-06-24T05:27:48.007 回答