I am trying to build my portfolio and I am developing an online store for books. Each user can register his own book where book is a different model. I want to make multiple registration forms for different categories (and subcategories) and I do not know how.
I am new in Ruby on Rails and I tried to google but I have not found anything useful. Moreover, I do not really know what to search since I do not have enough knowledge. Can someone show an example please? I really want to figure it out.
One of the main problem for me is to handle my database. Since every category has its own forms, there should be different columns in my book table. At the same time, I read that columns may effect on the website speed. Do I have to create a table for each category or I can simple add many columns and set default value to nil?
Some resources I found:
It sounds like your first problem is how to design the database. While I would not worry about having too many columns from a speed perspective (you need to have a lot of columns and rows for this to be a problem), having a large number of null columns is a sign that the database design is faulty.
I would suggest having a book
table containing common fields (id, title, ISBN, primary author or primary author ID, synopsis, category_type). You can then have related tables that use a 1:1 relationship with a Book, e.g. book_engineering
, book_law
, etc.
When you have a new form page, you will not know which form to show, since the user has not entered any data yet. Perhaps you can let them set the common Book data, and when they select from a drop-down category menu, you render the category-specific fields in response. Your INSERT
when the form is submitted will then be to the book
table plus a sub-category table that is determined at that time.
Finally, the other thing to think about is whether you could know about the book category before any details have been entered at all. For example if you have a link/button that says "Click here to enter a law book" then you can redirect to the form with a query string of ?category_type=4
and render all fields (including the subtable fields) straight away. This is really a question of UI design. It may be worth considering whether users are allows to change the category type as well, in which case you'd have to delete one subtable row and add another.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments