Validating throwaway forms not related to a model
I have a fo开发者_Python百科rm which takes in data, but it is not stored in any model. Instead, it is used to perform calculations and modify a model. Is there any way I can validate the data on the form (for example, forcing certain inputs to be of integer form) within rails, and without writing it manually in javascript?
Because of the rails mantra of "keep your controllers skinny", you should put your validations in your models. However you are stating that this data isn't backed by a database. This is ok, since you can create objects that act like a model(which means you can still have the activerecord validations in there).
I would highly suggest reading Yehuda Katz's post on ActiveModel: Make Any Ruby Object Feel Like ActiveRecord. From there you can use the ActiveRecord validations that you've been used to!
精彩评论