Different registration model for each category Rails

Anton Sergeyev

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:

A better method of handling multistep forms in rails

Multi Model Sign-up Wizard

Creating a sign up form flow in Ruby on Rails Part 1

halfer

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.

edited at
0

Comments

0 comments
Login to comment

Related

Rails app with different session store for each model

Registration of different users in Rails?

Find category within category model - Rails

Proper handling of Category model in Rails

Filtering each by category in model - ember.js

Rails, Devise remove registration of specific model

Query different number of records for each category in SQL

R: Caculating new variable by category with a different equation for each category

Multiple Category Models vs Single Category Model with STI? - Rails

Get latest record for each category with Rails or SQL

Rails model validation in different context

Same Model with different columns Rails

Accessing different model elements in Rails

Creating a Model in Rails within the controller of a different Model

Highcharts stacked column how to use different label on each category

Highcharts: How to give a different color to each category in barcharts?

Efficient way to select one from each category - Rails

The results after each training keras model are different

Associate Rails active model with two different models

Different types of Model fields in ruby on rails?

Rails: Calling methods in a model in a different controller

Rails: Add form from different model

show different toast for each flash in rails

Ruby on Rails - Different elements for each do slices

Report only first event of of model for each item - Rails model/view

How to set different horizontal (category) labels for each different product in MS Excel line chart

Implementing a multi-input model in Keras, each with a different sample sizes each (different batch sizes each)

How to use scope of a model, in a different model's controller in rails 4

How to update different columns on different views on Rails 4 for the same Model?