views:

44

answers:

2

Hello, I've been building an app recently that has a model Books that is a database table and linked to several models/controllers. I recently learned that instead of Books it needs to be called publications (just an example)...

I now want to update the database and all the mentions throughout the app. Is there a simple way to do that in Rails 3. Or do I have to migrate that particular table (via version?) and manually update all the references throughout the app?

Thanks

+1  A: 

EDIT

You can continue using the same models and hence keep the references throughout the app. Just that, because of your new database schema you'll have to set the table name for the particular model.Also you can use the alias_attribute method, to so you can continue referring to the old attribute names even if you have changed the column names in your table.For ex:

class Book < ActiveRecord::Base
    set_table_name 'publications'
    set_primary_key 'id'
    alias_attribute :id,:publication_id
end
Shreyas Satish
Thanks. that's a nice thing to know. Given my app is only a few weeks in and I don't have any real data, I'd rather not monkey patch it just yet. So I guess it's going to be 100% manual!
AnApprentice
A: 

No, there's no way to automatically rename a model.

My suggestion would be to simply delete the model and recreate it with a new name, as that's usually easier than to rename all files generated when you create one. Make sure your migrations are correct, though!

As for the code, however, you'll have to do that the hard way. Some text editors can do search/replace over multiple files, which could be handy.

vonconrad