refactoring code for attendance button
This commit is contained in:
parent
522f0b31d9
commit
ff6f53aec2
3 changed files with 30 additions and 46 deletions
|
|
@ -11,7 +11,8 @@ module Admin
|
|||
@attended = @conference.registrations.where('attended = ?', true).count
|
||||
end
|
||||
|
||||
def edit; end
|
||||
def edit;
|
||||
end
|
||||
|
||||
def update
|
||||
@registration.update_attributes(registration_params)
|
||||
|
|
@ -36,45 +37,22 @@ module Admin
|
|||
end
|
||||
end
|
||||
|
||||
=begin
|
||||
def present
|
||||
@registration.attended = true
|
||||
if @registration.save
|
||||
flash[:notice] = "#{@user.email} has attended"
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
else
|
||||
flash[:notice] = "Update Attended for #{@user.email} failed!" \
|
||||
"#{@registration.errors.full_messages.join('. ')}"
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
end
|
||||
end
|
||||
|
||||
def absent
|
||||
@registration.attended = false
|
||||
if @registration.save
|
||||
flash[:notice] = "#{@user.email} has not attended"
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
else
|
||||
flash[:notice] = "Update Attended for #{@user.email} failed!" \
|
||||
"#{@registration.errors.full_messages.join('. ')}"
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
def toggle_attendance
|
||||
if params[:attended] == "true"
|
||||
flash[:notice] = "#{@user.email} is attended."
|
||||
@registration.attended = true
|
||||
elsif params[:attended] == "false"
|
||||
flash[:notice] = "#{@user.email} is not attended."
|
||||
@registration.attended = false
|
||||
case params[:attended]
|
||||
when "true"
|
||||
@registration.attended = true
|
||||
when "false"
|
||||
@registration.attended = false
|
||||
else
|
||||
# redirect_to action: :index,
|
||||
# error: 'Wrong url path.')
|
||||
end
|
||||
unless @registration.save
|
||||
flash[:notice] = "Update Attended for #{@user.email} failed!" \
|
||||
"#{@registration.errors.full_messages.join('. ')}"
|
||||
|
||||
if @registration.save
|
||||
head :ok
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
render json: {attended: @registration.attended}
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
@ -86,13 +64,13 @@ module Admin
|
|||
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 ])
|
||||
:conference_id, :arrival, :departure,
|
||||
:volunteer,
|
||||
vchoice_ids: [], qanswer_ids: [],
|
||||
qanswers_attributes: [],
|
||||
user_attributes: [
|
||||
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages,
|
||||
:nickname, :affiliation])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue