Hi,
I am trying to finish building a Rails "Home Inventory" app as an example to help me learn rails. Following gives a general overview of what I am trying to achieve:
The main purpose of this application is to show a page with detailed information.
So, http://localhost:3000/living-room-couch would display the information regarding the couch.
Each Item, can belong one( or has one?) of three categories:
- Book
- Furniture
- Electronics.
Book has the following properties:
- isbn,
- pages,
- address,
- category
Furniture has following properties:
- color,
- price,
- address,
- category
Electronics has following properties:
- name,
- voltage,
- address,
- category.
--
Now on my View side, I have made 3 templates in rails, that contain elements suited to display an item belonging to one of the 3 categories. Template for Book shows isbn, and template for Electronics shows the voltage.
How do I model this in ActiveRecord? I will put it in English, maybe someone can help translate into Rails:
An Item, belongs_to or has_one category. Category can be one of the three: Book, Furniture, or Electronic.
I don't know how to do this. I know that each category like Book will be a model of its own, due to having different characteristics.
Do I need to have Category has a model too, because it would only consist of Book, or Furniture or Electronics. If I was to take the route of making Category a model of its own, how would I make it relate to a model such as Book.
--or
Would I just go this route (or join model perhaps):
class BookModel < ActiveRecord::Base
has_many :categories
End
And then, select to which category belongs, based on the Model name.
I hope I put the question right, I am just so confused regarding this.
Thank You for your time.