Class: InnerPlan::GroupsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/inner_plan/groups_controller.rb', line 29

def create
  @group = InnerPlan::List.new(group_params)
  @group.list = InnerPlan::List.root.find(params[:list_id])
  @group.user = current_inner_plan_user
  @group.position = :last

  if @group.save
    redirect_to @group.list
  else
    render :new, status: :unprocessable_entity
  end
end

#editObject



8
9
10
11
# File 'app/controllers/inner_plan/groups_controller.rb', line 8

def edit
  @group = InnerPlan::List.sub.find(params[:id])
  render InnerPlan::Groups::EditView.new(group: @group)
end

#newObject



23
24
25
26
27
# File 'app/controllers/inner_plan/groups_controller.rb', line 23

def new
  @list = InnerPlan::List.root.find(params[:list_id])
  @group = @list.lists.new(params[:id])
  render InnerPlan::Groups::NewView.new(group: @group)
end

#showObject



3
4
5
6
# File 'app/controllers/inner_plan/groups_controller.rb', line 3

def show
  @group = InnerPlan::List.sub.find(params[:id])
  render InnerPlan::Groups::ShowView.new(group: @group)
end

#updateObject



13
14
15
16
17
18
19
20
21
# File 'app/controllers/inner_plan/groups_controller.rb', line 13

def update
  @group = InnerPlan::List.sub.find(params[:id])

  if @group.update(group_params)
    redirect_to group_path(@group)
  else
    render :edit, status: :unprocessable_entity
  end
end

#update_positionObject



42
43
44
45
46
47
# File 'app/controllers/inner_plan/groups_controller.rb', line 42

def update_position
  @group = InnerPlan::List.sub.find(params[:id])
  @group.position = { before: update_positions_params[:position][:before] }
  @group.list = InnerPlan::List.root.find(update_positions_params[:list_id]) if update_positions_params[:list_id]
  @group.save!
end