2013-07-12 15:22:03 +00:00
|
|
|
class Profiles::GroupsController < ApplicationController
|
|
|
|
layout "profile"
|
|
|
|
|
|
|
|
def index
|
2013-08-06 15:03:13 +00:00
|
|
|
@user_groups = current_user.users_groups.page(params[:page]).per(20)
|
2013-07-12 15:22:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def leave
|
|
|
|
@users_group = group.users_groups.where(user_id: current_user.id).first
|
|
|
|
|
2013-09-26 11:49:22 +00:00
|
|
|
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.")
|
2013-07-12 15:22:03 +00:00
|
|
|
else
|
|
|
|
@users_group.destroy
|
|
|
|
redirect_to(profile_groups_path, info: "You left #{group.name} group.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group
|
|
|
|
@group ||= Group.find_by_path(params[:id])
|
|
|
|
end
|
|
|
|
end
|