Hi, Is there a clean way I could use one model and controller, but maps to different physical tables? For example, I have a large photo site, broken down into type "A" and type "B" such as siteA.mysite.com and siteB.mysite.com. Lets assume few things first: - 1 rails app - I have two tables in database: siteA_pictures and siteB_pictures. - I have two controllers one for each site to upload photo (code should be the same, maybe one controller should be shared in this case?) 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. So sharing same model code and perhaps controller code, but should input data into separate tables. Thanks. Truong. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
hi there, I perfectly understand what you''ve described, here''s more details and why I''m looking for a solution - I have a legacy application that already has this in place (tables and stuff) and that application still uses this database - say there are 500 customers and each customer has 4-5 special tables that have 10-50 millions rows I understand this database desing is not perfect, I''m trying to come up with a quick and dirty temporary web app using rails and this database schema. I found "Dr Nics Magic Models" (http://magicmodels.rubyforge.org/), but by some reason it doesn''t work (syntax errors etc.) best, --Alex Stephen Bartholomew wrote:>> 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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Truong-an Thai wrote:> Hi, > > Is there a clean way I could use one model and controller, but maps to > different physical tables? > > For example, I have a large photo site, broken down into type "A" and > type "B" such as siteA.mysite.com and siteB.mysite.com. > > Lets assume few things first: > - 1 rails app > - I have two tables in database: siteA_pictures and siteB_pictures. > - I have two controllers one for each site to upload photo (code should > be the same, maybe one controller should be shared in this case?) > > > 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. > > So sharing same model code and perhaps controller code, but should input > data into separate tables.Do you also want the same server instance to serve the siteA / siteB requests? If not you can put an entry in the file config/environment.rb> > Thanks. > > Truong.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2/3/07, Alex K... <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > hi there, > > I perfectly understand what you''ve described, here''s more details and > why I''m looking for a solution > > - I have a legacy application that already has this in place (tables and > stuff) and that application still uses this database > - say there are 500 customers and each customer has 4-5 special tables > that have 10-50 millions rows > > I understand this database desing is not perfect, I''m trying to come up > with a quick and dirty temporary web app using rails and this database > schema. > > I found "Dr Nic''s Magic Models" (http://magicmodels.rubyforge.org/), but > by some reason it doesn''t work (syntax errors etc.)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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---