mohamed
mohamed

Reputation: 135

Error using if in a content_tag

I am confused with this error. I am new to rails and I can't figure it out.

<% flash.each do |name,msg| %>
  <div class='alert alert-<%="#{name}"%>' >
    <a href="#" class='close' data-dismiss='alert' &#215; ></a>
    <%= content_tag :div , msg, :id => "flash_#{name}" if msg.is_a?(String); %>        
  </div>
<% end %>

Error message is:

syntax error, unexpected ')' if msg.is_a?(String); );@output_buffer.safe_append=' ^ /home/mody/Desktop/rails_apps/testing/app/views/layouts/application.html.erb:51: syntax error, unexpected keyword_ensure, expecting ')' /home/mody/Desktop/rails_apps/testing/app/views/layouts/application.html.erb:53: syntax error, unexpected keyword_end, expecting ')'

Upvotes: 0

Views: 687

Answers (1)

Wes Foster
Wes Foster

Reputation: 8900

Lots of syntactical problems here. Change your line to the following:

<%= content_tag(:div, msg, {:id => "flash_#{name}"}) if msg.is_a?(String) %>
  1. You should wrap your content_tag arguments inside of parentheses to ensure that Ruby does not get confused when introducing the if condition
  2. Ruby does not require a semi-colon at the end of a line

Upvotes: 1

Related Questions