Hi, I wanted to know where validations placed are most effective: Model, View or controller. In my application i enter data in a text box and if it is greater than a given value (which varies depending on choice), it should throw an error message and data shouldn''t be saved. Thanks, Premanshu -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 3, 2010, at 9:07 AM, Premanshu Mishra wrote:> Hi, > > I wanted to know where validations placed are most effective: Model, > View or controller. > > In my application i enter data in a text box and if it is greater > than a > given value (which varies depending on choice), it should throw an > error > message and data shouldn''t be saved. > > Thanks, > PremanshuYou''ve answered your own question here. The Model is responsible for saving data back to your persistence store (whatever that is) so that is the logical place for validations to live. More than one controller can access and send data to your one and only model, they should never repeat your validations there (DRY). Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Nov 3, 2010 at 7:07 AM, Premanshu Mishra <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Hi, > > I wanted to know where validations placed are most effective: Model, > View or controller. >Always in the models. You can do client side (browser Javascript) validations but those should only be in addition to server side for security. Controllers should be kept as lean as possible and used for directing traffic, not "business logic" such as validations. See: http://edgeguides.rubyonrails.org/3_0_release_notes.html> > In my application i enter data in a text box and if it is greater than a > given value (which varies depending on choice), it should throw an error > message and data shouldn''t be saved. > > Thanks, > Premanshu > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.