Will Schenk
2005-Mar-16 04:29 UTC
subdomaining questions: default routes and db partitioning (ThreadLocals?)
I''m working on adding subdomain mapping to my blog/bbs/aim/whatever program myelinate. I''m following the idiom of added a before filter in application.rb to look up my "Site" object, and setting that in the base controller. It''s accessable in all the views, so pulling things like the title out in a layout is working great. I''m also using the layout :function to choose which layout to render based upon the DB value. But a couple issues. 1) I''d like to be able to override the default route mapping -- some sites will, say, render EntryController.recent and some will render EntryController.show( site.default ). In the before filter I''m able to: c.params[:action] = ''show'' c.params[:id] = c.site.default_key which works great, but a) Is there a better way to do this using the route system? b) What''s the best way to determin that I''m hitting the default route? (i.e. "" )? 2) I''d like to have multiple sites running coexisting on one machine. Is the best way to do this having a ''site_id'' in every model that I want to partition, or is it to have a different schema for every domain? I can see advantages of both ways, but I''m leaning towards slightly more complicated SQL and much less DB maintence. So... I need a way to get to my site object inside of all my queries. Putting site as an attribute inside of the base controller works great for the controllers and the views; not so much for the models. I don''t want to pass in the site on every finder method because that would make me a little insane. I''m thinking about using a ThreadLocal (I''m not sure what the (non java) Ruby terminology is, but Thread.current[:site] is the Ruby code) from the model finder methods. Is there a cleaner way? Thanks, -w -- Will Schenk http://www.sublimeguile.com http://www.myelinate.com