0

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Same solution with more explanation: andrewtheis.net/blog/rails-3-and-form-errors.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.