views:

27

answers:

2

Hello,

I got the following situation:

I have a rails application and two databases, one is for the Rails Application and the second database (running on the same DB Server Instance) is for a different non-web application.

My Rails Web Application may read from the (second) Database directly via SQL but it can't write to it because of security restrictions (the data has to be validated by the non-web application). So we wrote a little CLI interface based on SOAP for writing into the database.

My question is: Can I extend the ActiveRecord Model (Rails 3) in a way so that the reading goes as normal over the SQL connection but update/create/delete goes over our selfmade interface.

Thanks for any response!

A: 

You could implement a tableless model: http://stackoverflow.com/questions/937429/activerecordbase-without-table-rails or http://github.com/AnthonyCaliendo/acts_without_database

Than you can set/get data into an object using the SOAP library.

rtacconi
A: 

Hello,

I think I found a good solution :)

@ rtacconi: Thanks for your links but since Rails 3 you don't have to use these extensions because ActiveModel works table-less out of the box :)

I need full ActiveRecord support for reading the table but writing is done over my SOAP interface. This is because I can't validate the data in my Rails application.

So my solution is to overload the ActiveRecord::Persistence Module (can be found in activerecord-3.0.0/lib/active_record/persistence.rb.

This module is responsible for any write tasks to the DB connection. So instead of writing to the DB, my Persistence Layer calls the SOAP interface.

Best regards

Simon

sled