Registration form working

This commit is contained in:
Godwin
2014-03-09 21:18:31 -06:00
parent 5e9e3d5fec
commit 4b79de7a24
4 changed files with 28 additions and 33 deletions
+17 -1
View File
@@ -34,12 +34,28 @@ class ConferencesController < ApplicationController
# PATCH/PUT /conferences/1
def update
if params[:register]
registration = ConferenceRegistration.find_by(:user_id => current_user.id, :conference_id => @conference.id)
if registration
registration.conference_registration_responses.destroy_all
else
registration = ConferenceRegistration.new(user_id: current_user.id, conference_id: @conference.id, is_attending: params[:is_attending])
end
data = Hash.new
params.each do |key, value|
matches = /^field_(\d+)(_(\d+|other))?/.match(key)
if matches
x
if matches[3] == nil
data[matches[1]] = value
else
data[matches[1]] ||= Hash.new
data[matches[1]][matches[3]] = value
end
end
end
data.each do |key, value|
registration.conference_registration_responses << ConferenceRegistrationResponse.new(registration_form_field_id: key.to_i, data: value.to_json.to_s)
end
registration.save!
render action: 'show'
elsif @conference.update(conference_params)
redirect_to @conference, notice: 'Conference was successfully updated.'