not displaying several html blocks if condition not met in ruby -


im trying restrict information being shown if data in not available.

in view.rb file, have this

<% if @content != nil %>  <div>    <h3>....</h3>     <% @content[0..3].each |something| %>        <li> .... <li>     <% end %>     <% @content[4..5].each |something| %>        <li> .... <li>     <% end %>     <% @content[5..11].each |something| %>        <li> .... <li>     <% end %>  <div> <% end %> 

how ever if content nil, lines content[4..5].each |something| being run , throwing errors obvious reasons.

how multiple blocks of html , ruby code ignored if condition isn't being met?

if code <% content[4..5].each |something| %> executed, @content not nil, there no way ruby wrong that.

but, if empty array or blank string pass test. in order cover wide range of possible "nil-like" values (nil, empty, blank...) use:

<% unless @content.blank? %> 

and let me know if helps.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -