Reputation: 13843
I am trying custom some error message
validates :username, :presence => {:message => 'Email cannot be blank'},
:uniqueness => {:message => 'Email was existed'}
but in the web page, it display like this:
Username Email cannot be blank
Username Invalid email format
Password Missing password
How can i get rid of the "Username" and "Password" in the very first word of each line??
(rails 3.0.7, ruby 1.9.2)
Thanks
Upvotes: 0
Views: 956
Reputation: 2638
Replace the code in the view that is displaying the errors with something like one of the examples below.
If you are using HAML:
- if @applicant.errors.any?
%ul
- @applicant.errors.each do |key, value|
%li= value
If you are using ERB: (the rails default template engine)
<% if @applicant.errors.any? %>
<ul>
<% @applicant.errors.each do |key, value| %>
<li><%= value %></li>
<% end %>
</ul>
<% end %>
Obviously there is a lot that can be done to style it, but I left that out for simplicity.
I hope this helps.
Upvotes: 2