Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

errors.full_messages format in rails 3

Got a small question in here.

My flash notice/alerts is inside [" "]

enter image description here

In my controller, I have to show the errors if the form isn't saved.

format.html { redirect_to  new_project_procurement_management_plan_path, alert:"#{@project_procurement_management_plan.errors.full_messages}"}

Here's how i put flash into views:

_alert.html.erb:

<% [:notice, :error, :alert].each do |level| %>
  <% unless flash[level].blank? %>
    <div class="alert alert-<%= flash_class(level) %>" id="flash">
      <a class="close" data-dismiss="alert" href="#">×</a>
      <%= content_tag :p, flash[level] %>
    </div>
  <% end %>
<% end %>

And in my helper file:

#Flash Message

    def flash_class(level)
        case level
        when :notice then "success"
        when :error then "error"
        when :alert then "error"
    end
  end

Now how can I remove my error display inside [" "]

Anyone knows where to configure it? Thanks.

EDIT

This is the validation message in my model:

def equality
    self.items.each do |item|
      errors.add(:base, "#{item.description.capitalize}: Quantity must be equal to the breakdown of quantity!") if item.months != item.qty
    end
  end
like image 202
xirukitepe Avatar asked Feb 23 '13 17:02

xirukitepe


1 Answers

errors.full_messages returns an array of all the error messages which is why you see the brackets and quotes. You can use .to_sentence to turn that array into a readable sentence.

@project_procurement_management_plan.errors.full_messages.to_sentence

like image 123
rocket scientist Avatar answered Nov 01 '22 22:11

rocket scientist