简体   繁体   中英

rails data field json, populate it from more form fields

I have table/model of projects and for each project I want to create table/model rewards. I don't know if one project will have 1 or 10 rewards so I thought that best might be to store it in one json data object to avoid creating fields in table like name1, name2, nameX. The question is how can I have more form fields and on submiting merge them and put in json data object? Or is there any other way how to do that and I am missing that? thanks

On the backend you need to have two tables: projects and rewards. On the client side have a look at nested forms: http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#M002132

Browser will automatically take hierarchical form data, serialize and send to server. Rails will then save the data in your models.

Here's a tutorial: http://railscasts.com/episodes/196-nested-model-form-part-1

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