Welcome Guest | Login

Changing ActiveRecord::Base.table_name_suffix in production mode

I just created my Hostingrails account and I'm about to set up my main rails app, but there's a problem I have to resolve first.  I'm using ActiveRecord::Base.table_name_suffix to change the working set of data for my application on the fly (I have code in a before filter in ApplicationController that handles it).  The problem is that in production mode, I can only assign a value to that variable once, then further assignments don't work, so it's stuck using whatever set of data gets chosen first (until I restart the server).  It works fine in development mode, so on my old host I had it running in development mode.  However, for both speed concerns and the fact that Railshosting prohibits apps from running in development mode, I need to get this working in production mode.  Is there any way I can do multiple assignments to ActiveRecord::Base.table_name_suffix in production mode without having to restart the app on each request? (which obviously isn't an acceptable solution)  If there's some other way to set the table name suffix globally I could use that too, but either way it has to work in production mode.

Thanks,
Brett

2007-03-21 04:46 PM

We'll have to think of a work-around - thank you for being on top of this -

You need to "change the working set of data for my application on the fly" --- tell me more about this, what exactly do you mean?  I'm confident we can help you out.  Thanks for posting.

~William

2007-03-22 02:11 AM

My app is designed to help students at my college plan out their schedule, so I have tables holding information on all the courses (and related info). I have data for multiple semesters in the database, and each set of tables is named with a suffix for their semester. For example, the tables that hold courses and instructors for the spring 07 semester are named 'courses_S07' and 'instructors_S07'. This way, to change which semester of data the app is working with, I can just change the global table name suffix to the string for that semester. The problem is that I can only change this suffix once every time the server is started (in production mode).  So far I've only run it with fcgi, I assume it would behave the same under mongrel in production mode.  The switching is done by a before filter in ApplicationController by checking for a 'semester' value in params. Let me know if you need more explanation.

-Brett

2007-03-22 01:49 PM

It sounds like your workaround is to have semester column in the table and just work with one table for students and one for instructors.  You'll be writing the same amount of information to the database and all you'd need to do is have the :conditions => ['semester = ?', @semester] where @semester was the 'S07' -- would that work?  You'll find that will give you more flexibility in the long run, too.

~William

2007-03-25 03:26 AM

I was just able to figure out a way to get the dynamic table name changes working in production mode. It's a bit of a dirty hack, but it works. I had thought about adding a column to each table for the semester when I was originally writing it, but I'd have to change a lot of code for that, and I like having the data separated into different tables. It makes updating individual semesters much easier. Thanks for the replies, I'm glad to finally have this working.

-Brett

2007-03-25 04:44 AM

OK - cool - sometimes the dirty hacks are needed...'glad it working for you.

2007-03-25 04:59 AM


Hello Guest! In order to post you must be an active client with us, please log in or sign up today!