Class: NippoCore::GroupsController

Inherits:
ApplicationController show all
Includes:
Pundit
Defined in:
app/controllers/nippo_core/groups_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
# File 'app/controllers/nippo_core/groups_controller.rb', line 21

def create
  if @group.save
    current_user.add_member(current_user, @group)
    redirect_to root_path
  else
    render 'new', status: 400
  end
end

#editObject



30
31
32
33
# File 'app/controllers/nippo_core/groups_controller.rb', line 30

def edit
  authorize @group
  render layout: nil
end

#indexObject



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

def index
  @groups = NippoCore::Group.order(created_at: :desc).page(params[:page]).per(10)
end

#newObject



12
13
# File 'app/controllers/nippo_core/groups_controller.rb', line 12

def new
end

#request_joinObject



44
45
46
47
# File 'app/controllers/nippo_core/groups_controller.rb', line 44

def request_join
  result = current_user.send_request(@group)
  render layout: nil
end

#showObject



15
16
17
18
19
# File 'app/controllers/nippo_core/groups_controller.rb', line 15

def show
  @reports = @group.reports.order(reported_at: :desc).limit(5)
  @requests = @group.unaccepted_requests.limit(5)
  @members = @group.members
end

#updateObject



35
36
37
38
39
40
41
42
# File 'app/controllers/nippo_core/groups_controller.rb', line 35

def update
  authorize @group
  if @group.update(group_params)
    redirect_to @group
  else
    head 400
  end
end