Benton Lam
2006-Apr-13 08:13 UTC
[Rails] Would validation w/o ActiveRecord have clean sol''n?
Well I was using Rails for a class project, and frankly I love it. However I ran into situation that I want to use have a model object that doesn''t get stored into the database, and still have the same validation. The Rails wiki outlines a solution, but it''s still kind of a hack (e.g. I can''t create a new instance of the non-ActiveRecord model by passing a hash into initialize) I''m wondering if having some kind of base class that allows for validation functionality without hooking up to a DB is under consideration, or better yet, if there''s a clean solution for this type of problem already. -- Posted via http://www.ruby-forum.com/.
Wilson Bilkovich
2006-Apr-13 15:23 UTC
[Rails] Would validation w/o ActiveRecord have clean sol''n?
On 4/13/06, Benton Lam <calyth@gmail.com> wrote:> Well I was using Rails for a class project, and frankly I love it. > However I ran into situation that I want to use have a model object that > doesn''t get stored into the database, and still have the same > validation. > The Rails wiki outlines a solution, but it''s still kind of a hack (e.g. > I can''t create a new instance of the non-ActiveRecord model by passing a > hash into initialize) > I''m wondering if having some kind of base class that allows for > validation functionality without hooking up to a DB is under > consideration, or better yet, if there''s a clean solution for this type > of problem already. >The "Rails Recipes" book has a decent solution for this. Basically, you just need to make sure a few (empty) methods are available in the class you want to validate.