Search code examples
rubyruby-on-rails-3ruby-on-rails-3.1

Make error show conditional message?


How would I get my error message to be conditional like this:

<% if object.errors.any? %>

  <% if object.errors.count = 1 %>
    Oops, an error was found.
  <% else %>
    Oops, <%= pluralize(object.errors.count, "errors") %> were found
  <% end %>

  <% object.errors.full_messages.each do |msg| %>
    <%= msg %>
  <% end %>

<% end %>

I get a undefined method count= error right now. What would be the correct way?


Solution

  • where you have

     <% if object.errors.count = 1 %>
    

    you need to have:

     <% if object.errors.count == 1 %>
    

    note the double equal sign.