views:

31

answers:

1

there are 2 ways to write validations in RoR3.

  validates_length_of :name, :minimum => 5    
  validates :name, :length => { :minimum => 5 }

both will give the same.

i wonder where i can read more about the latter one. all the options for it.

cause the http://guides.rails.info/activerecord_validations_callbacks.html just mention the first type.

the latter one is better for validating by field and not by validation type.

then you can have all validations for one field in one row.

thanks

+2  A: 

Perhaps this will be helpful for you: http://asciicasts.com/episodes/211-validations-in-rails-3.

The first syntax is just for backwards compatibility, works just as it does in Rails 2. The latter syntax is a bit more complex and im afraid there isn't a proper documentation on it yet anywhere. You can just google and take bits and pieces from various blog posts etc.

Tanel Suurhans
you are sure the latter one is for rails 3? so then i SHOULD use the latter one i guess? it feels better to have all options for one field.
never_had_a_name