Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add if statement to do-end block

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!

like image 705
Peter Tretyakov Avatar asked Jun 24 '13 05:06

Peter Tretyakov


People also ask

How do you end an if statement?

An IF statement is executed based on the occurrence of a certain condition. IF statements must begin with the keyword IF and terminate with the keyword END.

Which statement is used to add in the end of the IF statement?

Use the END statement to terminate a BASIC program or a section of an IF statement, , or OPEN statement. An END statement is the last statement in a BASIC program; it indicates the logical end of the program.


1 Answers

You have to use like :

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

Or using if statement after the block :

<%= content_tag(:div, class: 'some_class') do %>
    ...
<% end if .......%>
like image 134
Muntasim Avatar answered Oct 05 '22 23:10

Muntasim