groups_controller.rb 623 Bytes
Newer Older
1
2
3
4
class Profiles::GroupsController < ApplicationController
  layout "profile"

  def index
5
    @user_groups = current_user.users_groups.page(params[:page]).per(20)
6
7
8
9
10
  end

  def leave
    @users_group = group.users_groups.where(user_id: current_user.id).first

11
12
    if group.last_owner?(current_user)
      redirect_to(profile_groups_path, alert: "You can't leave group. You must add at least one more owner to it.")
13
14
15
16
17
18
19
20
21
    else
      @users_group.destroy
      redirect_to(profile_groups_path, info: "You left #{group.name} group.")
    end
  end

  private

  def group
skv's avatar
skv committed
22
    @group ||= Group.find_by(path: params[:id])
23
24
  end
end