Yuval Karmi
Yuval Karmi

Reputation: 26713

Is it possible to put validations in controllers in Ruby on Rails?

I have an additional member method (and a corresponding route) called download, for which I'd like to validate the existence of a password field. Putting :validates_presence_of :password in my download method, I get an error claiming it's an undefined method.

Is this possible?

Upvotes: 0

Views: 74

Answers (1)

Chuck Vose
Chuck Vose

Reputation: 4580

No, you can add errors to the model but validations live in the model. Check out the errors methods and add_to_base if you need to add errors in the controller for whatever reason.

Upvotes: 2

Related Questions