Topic: Optimizing Code for Bookselling Site

Hi there

I'm a little new to RoR.  I'm building a book selling site for 10 different cities.  I have a working codebase that works for one city.  I have an Item model that maps to an Items table.  I want to expand to incorporate the other cities, but I'm not sure if I should have different Item table for each city.  If I wanted a different table for each city, would I need a separate model and controller and view?

Re: Optimizing Code for Bookselling Site

It would be better to have 1 cities table, and 1 items table.. You simply have a column in your items table called 'city_id' that refers to the id of one of the cities in your City table.
Then you can use active record associations (has_many :ites, and belongs_to :city) to utilize that relationship in your code.

Re: Optimizing Code for Bookselling Site

but if I did it like that...wouldn't I need every form to have a field with the city name?

I'm thinking of each city having their own subdomain and then deploying the same codebase to each subdomain with a variable that tells it which table to this feasible?

Last edited by georgecamp (2008-02-13 14:56:25)

Re: Optimizing Code for Bookselling Site

I think the one table is better.

The form doesn't need to have a field ... because items have a relationship with cities. So you know the city the item belongs to already.

Toby Hede
FiniteStateMachine - Software Development for Social Networks