The Rails application I'm working on, has two central pieces: users and groups. A user registers through a form, and is added to the users table.
The groups table has four primary columns: name, title, description, and membership.
Groups are handled in two steps.
- Step1: the admin creates the group (name, title, description).
- Step2: Membership is a JSON field. Admin needs to log in using a second form, and add/edit that JSON structure's fields: group owner, group admins, members, parse / re-parse into a JSON and update the groups table.
The user signup, and groups creation form are working fine. The problem is the second form: creating the group's membership. I am not really sure how to proceed.
What I did is create the link and routes to properly select from the groups, and produce a REST call with the correct params by adding additional routes and links on the Show page. I verified that the l ink is correct, when I hover over it, I see http://myapp.com/groups/3/admin (3 is the correct ID in the groups table).
The methods in my groups_controller.rb are similar to the following:
def show
@group = Group.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @group }
end
end
I created a groups_admin.html.erb and put it in the views/groups folder. It has in it the logic to construct a set of drop down boxes, allowing the admin to pick from the users list to fill the group membership (the functions are in the groups helper).
What I don't know is how to complete it with a form declaration, etc. in groups_admin.html.erb and what to add to the groups_controller.rb to cause an UPDATE to that particular row (after I turn the returned fields into a JSON). So far, here's what I have added to it
def admins
end
Changing the groups table schema and creating additional groups_admins, groups_owners, groups_members tables is not an option. Any ideas?