seeking guidance for structuring e-commerce rails application

Go To StackoverFlow.com

3

I'm looking for some guidance for a personal project of mine in RoR. I learned RoR using Michael Hartl's online book, and now I am building a different application for my own edification.

My web application will be similar to an e-commerce website, except instead of selling products, I'll be selling menu items from a restaurant. I have already implemented a users resource which stores basic information (name, email etc.), but I am seeking guidance about the restaurant resource.

The restaurant 'show' page should display the restaurant name, a paragraph description of the restaurant, 3-5 photographs, a few descriptive tags, and a full menu with the dish names and prices. How should I attack this databasing problem? I am considering creating three models here, something like the following:

class Restaurant < ActiveRecord::Base
 has_many :dishes, :through => :menus
end

class Menu < ActiveRecord::Base
 belongs_to :restaurant
end

class Dish < ActiveRecord::Base
 belongs_to :menu
 has_one :restaurant, :through :menus
end

Is that the right approach?

I have two concerns about this:

1) A string attribute in the database is limited to 255 characters, not nearly enough to store a restaurant description. How do I proceed here? I'd like to make it easy for the description to be edited by an admin user.

2) How do I handle the pictures? I did some searching and some people have suggested CarrierWave for attachment uploading. Does anyone have any other suggestions or alternatives? These photos should be easily changeable by an admin user, and they should belong to a restaurant.

Thanks for your help.

2012-04-04 01:06
by Tushar Garg
Your associations look good. Dishes can just clump in a database and Menu rows can organize the dishes into usable sets per restaurant. For managing uploads, if you plan on using Heroku, check out this add-on: https://devcenter.heroku.com/articles/progstr-file - danneu 2012-04-04 01:20
Thank you for your response, yes I plan on deploying to Heroku so this should come in handy - Tushar Garg 2012-04-04 02:14
@danneu I edited the post to reflect the other models as well. Does that sound right to you - Tushar Garg 2012-04-04 14:38


2

Yes, that's a fine way to do it.

To store more text in a database table field, use "text" like this:

create_table :products do |t|
  t.string :name
  t.text :description
end

Yes, choose CarrierWave. Some alternatives:

  • Paperclip (quite good)
  • Rolling your own (bad idea unless you like learning)
  • various JavaScript/jQuery/AJAX upload helpers (really slick yet more complex)
2012-04-04 01:12
by joelparkerhenderson
Thanks for your detailed response. One more question: how would you handle tags? Create an association such as: hasmany :tags / hasmany :restaurants ? I want to be able to sort/view restaurants by tag (Chinese, Open late, etc.. - Tushar Garg 2012-04-04 02:25
For tagging, use acts-as-taggable-on https://github.com/mbleigh/acts-as-taggable-o - joelparkerhenderson 2012-04-04 03:00