I think perhaps I have not phrased this very well, and that explains
the lack of replies.
I have a number of ActiveRecord models all based around an ‘Order
Model’, a shortened version of which is shown below.
class Order < ActiveRecord::Base
All of the other models belong to order.
I wish to validate the various models such as applicant,
current_address etc differently based upon the company attribute of
I have developed a solution to this which involved a complete hand-
rolled validation suite, supporting all of the standard activeRecord
validators. This solution was developed with a number of tables such
as model, fields, field_items etc that described the validation and
amounts to quite a lot of data.
I now have to manipulate this data and copy and edit it for each new
company that I am connecting to. This is tedious and error prone.
Whilst reading ‘The Rails Way’, I found a section where Obie F.
described keeping the validation code in the database in the form of
ActiveRecord validation statements and injecting these into the models
at runtime based upon the value of the company id.
I am imagining keeping data in tables such as the following :-
Code validates_length_of :middle_name, :maximum => 20, :allow_nil =>
Code validates_length_of :middle_name, :maximum => 1, :allow_nil =>
So for company 201 a middle name of ‘John’ would fail validation but
that would be ok for company 200.
Has anyone seen this done, and if so do they have any tips/suggestions
on how to do it, even better does anyone have any links to tutorials/
code that does this?