Class: LatoSpaces::GroupsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#setgroup, #setpreferred

Methods included from Groupable

#authenticate_group, #session_group_create

Instance Method Details

#createObject



23
24
25
# File 'app/controllers/lato_spaces/groups_controller.rb', line 23

def create
  @group = LatoSpaces::Group.new
end

#create_actionObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/lato_spaces/groups_controller.rb', line 27

def create_action
  @group = LatoSpaces::Group.new(group_params)

  respond_to do |format|
    if @group.save && @group.lato_spaces_memberships.create(lato_user_id: @session.user_id)
      redirect = lato_spaces.groups_show_path(@group)
      redirect = lato_spaces.root_path unless @session.user.lato_spaces_admin

      format.html { redirect_to redirect, notice: 'Group was successfully created.' }
      format.json { render json: @group }
    else
      format.html { render :create, status: :unprocessable_entity }
      format.json { render json: @group.errors, status: :unprocessable_entity }
    end
  end
end

#destroy_actionObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/lato_spaces/groups_controller.rb', line 74

def destroy_action
  respond_to do |format|
    if @group.destroy
      redirect = lato_spaces.groups_path
      redirect = lato_spaces.root_path unless @session.user.lato_spaces_admin

      format.html { redirect_to redirect, notice: 'Group was successfully destroyed.' }
      format.json { render json: @group }
    else
      format.html { redirect_to lato_spaces.groups_show_path(@group), notice: 'Group was not destroyed.' }
      format.json { render json: @group.errors, status: :unprocessable_entity }
    end
  end
end

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/lato_spaces/groups_controller.rb', line 8

def index
  columns = %i[name actions]
  sortable_columns = %i[name]
  searchable_columns = %i[name]

  @groups = lato_index_collection(
    LatoSpaces::Group.all,
    columns: columns,
    sortable_columns: sortable_columns,
    searchable_columns: searchable_columns,
    default_sort_by: 'name|ASC',
    pagination: true
  )
end

#showObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/lato_spaces/groups_controller.rb', line 44

def show
  columns = %i[user_infos actions]
  sortable_columns = %i[user_infos]
  searchable_columns = %i[user_infos]

  @memberships = lato_index_collection(
    @group.lato_spaces_memberships,
    columns: columns,
    sortable_columns: sortable_columns,
    searchable_columns: searchable_columns,
    default_sort_by: 'user_infos|ASC',
    pagination: true
  )
end

#updateObject



59
60
# File 'app/controllers/lato_spaces/groups_controller.rb', line 59

def update
end

#update_actionObject



62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/lato_spaces/groups_controller.rb', line 62

def update_action
  respond_to do |format|
    if @group.update(group_params)
      format.html { redirect_to lato_spaces.groups_show_path(@group), notice: 'Group was successfully updated.' }
      format.json { render json: @group }
    else
      format.html { render :show, status: :unprocessable_entity }
      format.json { render json: @group.errors, status: :unprocessable_entity }
    end
  end
end