First checkin
This commit is contained in:
parent
f207e2c8b7
commit
90b30db9e8
260 changed files with 37349 additions and 0 deletions
51
app/controllers/conference_registration_controller.rb
Normal file
51
app/controllers/conference_registration_controller.rb
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
class ConferenceRegistrationController < ApplicationController
|
||||
before_filter :verify_user
|
||||
|
||||
def register
|
||||
# TODO Figure out how to change the route's id from :id to :conference_id
|
||||
@conference = Conference.find_all_by_short_title(params[:id]).first
|
||||
@person = current_user.person
|
||||
@registration = @person.registrations.where(:conference_id => @conference.id).first
|
||||
@registered = true
|
||||
if @registration.nil?
|
||||
@registered = false
|
||||
@registration = @person.registrations.new(:conference_id => @conference.id)
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
conference = Conference.find_all_by_short_title(params[:id]).first
|
||||
person = current_user.person
|
||||
registration = person.registrations.where(:conference_id => conference.id).first
|
||||
update_registration = true
|
||||
begin
|
||||
if registration.nil?
|
||||
update_registration = false
|
||||
person.update_attributes(params[:registration][:person_attributes])
|
||||
params[:registration].delete :person_attributes
|
||||
registration = person.registrations.new(params[:registration])
|
||||
registration.conference_id = conference.id
|
||||
registration.save!
|
||||
else
|
||||
registration.update_attributes!(params[:registration])
|
||||
end
|
||||
rescue Exception => e
|
||||
redirect_to(register_conference_path(:id => conference.short_title), :alert => 'Registration failed:' + e.message)
|
||||
return
|
||||
end
|
||||
|
||||
redirect_message = "You are now registered."
|
||||
if update_registration
|
||||
redirect_message = "Registration updated."
|
||||
end
|
||||
redirect_to(register_conference_path(:id => conference.short_title), :notice => redirect_message)
|
||||
end
|
||||
|
||||
def unregister
|
||||
conference = Conference.find_all_by_short_title(params[:id]).first
|
||||
person = current_user.person
|
||||
registration = person.registrations.where(:conference_id => conference.id).first
|
||||
registration.destroy
|
||||
redirect_to :root
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue