简体   繁体   中英

How to render different forms on show page

I have Event model with a kind column. The Event can be either a training camp, conference, etc.
Right now on every event page I display a form for a Customer so that a client can register for this particular Event. Customer belongs_to Event.

Now, I would like to have a new kind of Event and for this specific event I need to display additional fields in the form for the customer. Customer table does not have these columns. The fields should be like location, training date, parent name, parent phone, etc.

Of course, the new fields should be validated upon input. I know how to render different forms conditionally on the event show page but I am not quite sure where to add the new columns and how to handle it in the controller. I wouldn't like to add these columns to Customer table because I think they do not really belong there.
Besides, I need to validate the new fields as well so there will be a situation where I render different forms and I can't validate all the fields if just one specific form is rendered.

Do you have any ideas how I could go about this?

User attr_accessor in customer model for mass assigning the new fields

attr_accessor: :location,:training_date etc

Now you pass those values from form with model object . And you can right condition in "Pratial or View"

If you want store those values in DB table then you have to create columns in Customer Model. Or if you don't want to create fields in customer table then you can use " Redis " for storage the values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM