Got a small question in here.
My flash notice/alerts is inside [" "]
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With