Comparison of values: Validations

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

On Nov 3, 2010, at 9:07 AM, Premanshu M. wrote:

Thanks,
Premanshu

You’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

On Wed, Nov 3, 2010 at 7:07 AM, Premanshu M.
[email protected]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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs