[Rails] Rails project with no relational database component?

John W. Long ng at johnwlong.com
Sat Mar 19 05:04:50 GMT 2005


Jim Weirich wrote:
> I'm playing with a rails app that is just a view on some public directories.  
> The model objects are loaded from files in those directories.  I wrote a noop 
> connection adapter that just does nothing when connecting to the database.

A noop adapter? Why not just include ActiveRecord::Validations into your 
model?

Define a small class like this:

   class BaseRecord
     def save; end
     def update_attribute; end
     def new_record?; end
     include ActiveRecord::Validations

     def [](key)
       instance_variable_get(key)
     end
   end

This allows you to do regular validations on your model:

   class Address < BaseRecord
     attr_accessor :line_one, :line_two, :city, :province,
         :postal_code, :phone
     validates_presence_of :line_one, :city, :province,
         :postal_code, :message => "required"
   end

   a = Address.new

   a.valid? #=> false

I'd love to see the validation's part abstracted a little more away from 
ActiveRecord. (Move it into a module called Validateable.) It seems a 
little silly that inorder to use this great module we have to define 
three methods that don't have anything to do with validation.

--
John Long
http://wiseheartdesign.com



More information about the Rails mailing list