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.
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: