osem-fcy/app/controllers/admin/registrations_controller.rb
Chrisbr d21e19b977 Big refactoring of registration
- Added datatable gem
- Addaed datatable to events, users (#422), registrations
2014-08-22 15:08:54 +02:00

72 lines
2.5 KiB
Ruby

module Admin
class RegistrationsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference
before_filter :set_user, except: [:index]
def index
authorize! :show, Registration.new(conference_id: @conference.id)
@pdf_filename = "#{@conference.title}.pdf"
@registrations = @conference.registrations.includes(:user).order('registrations.created_at ASC')
@attended = @conference.registrations.where('attended = ?', true).count
end
def toogle_attended
@registration.attended = !@registration.attended
if @registration.save
flash[:notice] = "Successfully updated Attended for #{@user.email}"
redirect_to admin_conference_registrations_path(@conference.short_title)
else
flash[:notice] = "Update Attended for #{@user.email} failed!"
redirect_to admin_conference_registrations_path(@conference.short_title)
end
end
def edit
end
def update
@registration.update_attributes(registration_params)
if @registration.save
redirect_to admin_conference_registrations_path(@conference.short_title),
notice: 'Successfully updated registration!'
else
flash[:alert] = "A error prohibited the Registration for #{@conference.title}: "\
"#{@registration.errors.full_messages.join('. ')}."
render :edit
end
end
def destroy
if can? :destroy, @registration
@registration.destroy
redirect_to admin_conference_registrations_path(@conference.short_title),
notice: "Deleted registration for #{@user.name}!"
else
redirect_to(admin_conference_registrations_path(@conference.short_title),
alert: 'You must be an admin to delete a registration.')
end
end
protected
def set_user
@user = User.where('id = ?', @registration.user_id).first
end
def registration_params
params.require(:registration).
permit(
:conference_id, :arrival, :departure,
:volunteer,
vchoice_ids: [], qanswer_ids: [],
qanswers_attributes: [],
user_attributes: [
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages,
:nickname, :affiliation ],
supporter_registration_attributes: [
:id, :supporter_level_id, :code
])
end
end
end