Class: LatoSpaces::MembershipsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/lato_spaces/memberships_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#index, #setgroup, #setpreferred

Methods included from Groupable

#authenticate_group, #session_group_create

Instance Method Details

#createObject



7
8
9
# File 'app/controllers/lato_spaces/memberships_controller.rb', line 7

def create
  @membership = @group.lato_spaces_memberships.new
end

#create_actionObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/lato_spaces/memberships_controller.rb', line 11

def create_action
  @membership = @group.lato_spaces_memberships.new(membership_params)

  respond_to do |format|
    if @membership.save
      format.html { redirect_to lato_spaces.groups_show_path(@group), notice: 'Membership was successfully created.' }
      format.json { render json: @membership }
    else
      format.html { render :create, status: :unprocessable_entity }
      format.json { render json: @membership.errors, status: :unprocessable_entity }
    end
  end
end

#destroy_actionObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/lato_spaces/memberships_controller.rb', line 25

def destroy_action
  respond_to do |format|
    if @membership.destroy
      redirect = lato_spaces.groups_show_path(@membership.lato_spaces_group)
      redirect = lato_spaces.root_path if !@session.user.lato_spaces_admin && @membership.lato_user_id == @session.user_id

      format.html { redirect_to redirect, notice: 'Membership was successfully destroyed.' }
      format.json { head :no_content }
    else
      format.html { redirect_to lato_spaces.groups_show_path(@membership.lato_spaces_group), notice: 'Membership was not destroyed.' }
      format.json { render json: @membership.errors, status: :unprocessable_entity }
    end
  end
end

#send_invite_actionObject



40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/lato_spaces/memberships_controller.rb', line 40

def send_invite_action
  respond_to do |format|
    if @membership.send_invite
      format.html { redirect_to lato_spaces.groups_show_path(@membership.lato_spaces_group), notice: 'Invite was successfully sent.' }
      format.json { render json: @membership }
    else
      format.html { redirect_to lato_spaces.groups_show_path(@membership.lato_spaces_group), notice: 'Invite was not sent.' }
      format.json { render json: @membership.errors, status: :unprocessable_entity }
    end
  end
end