summaryrefslogtreecommitdiff
path: root/app/controllers/group_memberships_controller.rb
blob: e0f897b3a7816000136f09ead3fad5181e883f73 (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class GroupMembershipsController < ApplicationController
  load_and_authorize_resource :group
  load_and_authorize_resource :group_membership, :through => [:group]

  before_filter :spread_breadcrumbs

  def index
  end

  def show
  end

  def new
  end

  def create
    if params[:group_membership][:item_type].blank?
      params[:group_membership][:item_type] = @group.group_memberships.first.item_type
    end
    @group_membership = @group.group_memberships.new(params[:group_membership])
    if @group_membership.save
      redirect_to action: "index", :notice => t('group_memberships.controller.successfuly_created')
    else
      render :new
    end
  end

  def edit
  end

  def update
    if @group_membership.update_attributes(params[:group_membership])
      redirect_to action: "index", :notice  => t('group_memberships.controller.successfuly_updated')
    else
      render :edit
    end
  end

  def destroy
    @group_membership.destroy
    redirect_to action: "index", :notice => t('group_memberships.controller.successfuly_destroyed')
  end

  private
  def spread_breadcrumbs
    add_breadcrumb t("groups.index.page_title"), groups_path
    add_breadcrumb @group, group_path(@group)
    add_breadcrumb t("group_memberships.index.page_title"), group_group_memberships_path(@group)
    if @group_membership && !@group_membership.new_record?
      add_breadcrumb @group_membership, group_group_membership_path(@group, @group_membership)
    end
  end
end