Rails 'errors' variable (on form validation, etc)
I'm kinda new to rails (3) and I stumbled upon a small... doorstep. Does the model automatically create the "errors" variable when the verification fails (for a lack of better term)? 开发者_开发百科If so, is there a way to make it look neater somehow? Because the output can sometimes be like:
Username can't be less than 5 characters long
Username can't be blank
Username is ugly.
And I don't think that could look so much better.
P.S: The errors were from the top of my head, so they might not be too accurate.
(I'll keep you posted if I find something out. :)
Just use the 'message' method
class Account < ActiveRecord::Base
validates_exclusion_of :subdomain, :in => %w(www us ca jp),
:message => "Subdomain %{value} is reserved."
end
Have a look here : http://edgeguides.rubyonrails.org/active_record_validations_callbacks.html
精彩评论