small medium large xlarge

 

Pt-B-2

To solve the length validation try starting with writing the test first.

product = Product.new(:title => “too tiny”, :description => “this product has a title that is toooooo tiny”, :price => 0.5, :image_url => “tiny.gif”)

To customize error messages, you’ll want to change the translations. You can add customized translations in config/locales/en.yml for example. See Translating ActiveRecord for more info.

Dorian says:

Looking in the docs, I couldn’t find any way to customise the message when using the short form ‘validates’, so I switched to the long form ‘validates_uniqueness_of’:

validates_uniqueness_of :title, :message => “must be unique”

Page History
  • V14: Eric Ricketts [12 months ago]
  • V13: Eric Ricketts [12 months ago]
  • V12: Eric Ricketts [12 months ago]
  • V11: Eric Ricketts [12 months ago]
  • V11: Alex Emelyanov [over 3 years ago]
  • V10: Alex Emelyanov [over 3 years ago]
  • V9: Alex Emelyanov [over 3 years ago]
  • V8: Alex Emelyanov [over 3 years ago]
  • V7: Phillip J Ramey [about 5 years ago]
  • V6: Eric Treece [over 5 years ago]