One Model, multiple tables

I want a request to siteA.mysite.com/upload_photo to be able to input data into the siteA_pictures table and siteB.mysite.com/upload_photo respectively.

I think perhaps you need to question your database/system design. Would it not be better to have one 'pictures' table and include a 'site_id' in the table? I imagine that with your current idea you'll run in to more problems that just this one.

You could have a site model that has many pictures (or articles or posts etc). Your code would be nice and simple then:

class Site < ActiveRecord::Base    has_many :pictures end

class User < ActiveRecord::Base    belongs_to :site end

And for the controller code:

site = Site.find(site_id) site.pictures.find_by_name("my_dog.jpg")

You can pick up the site id using the url (siteb.mysite.com) and only pictures from that site would show.

Hope that helps,

Steve

Perhaps you could use set_table_name in a before filter? e.g.:

  def set_customer_tables     customer_id = find_customer_id     Foo.set_table_name "foos_#{customer_id}"     Bar.set_table_name "bars_#{customer_id}"     # etc.   end   before_filter :set_customer_tables