omninonsense
omninonsense

Reputation: 6882

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. :)

Upvotes: 1

Views: 493

Answers (1)

apneadiving
apneadiving

Reputation: 115531

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

Upvotes: 4

Related Questions