cirandas.net

ref: master

plugins/volunteers/controllers/myprofile/volunteers_plugin_myprofile_controller.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class VolunteersPluginMyprofileController < MyProfileController

  no_design_blocks

  # remove fake dependency
  helper OrdersPlugin::DateHelper

  def index

  end

  def toggle_assign
    @owner_id = params[:owner_id]
    @owner_type = params[:owner_type]
    @owner = @owner_type.constantize.find @owner_id
    @period = @owner.volunteers_periods.find params[:id]

    if profile.members.include? user
      @assignment = @period.assignments.where(profile_id: user.id).first
      if @assignment
        @assignment.destroy
      else
        @period.assignments.create! profile_id: user.id
      end
      @period.assignments.reload
    end

    render partial: 'volunteering', locals: {period: @period}
  end

  protected

end