Add view for StudyGroups

This commit is contained in:
Sebastian Serth
2018-12-14 14:52:04 +01:00
parent 9061a07763
commit 7983c0797a
13 changed files with 168 additions and 9 deletions

View File

@ -0,0 +1,48 @@
class StudyGroupsController < ApplicationController
include CommonBehavior
before_action :set_group, only: MEMBER_ACTIONS
def index
@search = StudyGroup.search(params[:q])
@study_groups = @search.result.includes(:consumer).order(:name).paginate(page: params[:page])
authorize!
end
def show
@search = @study_group.users.search(params[:q])
end
def edit
@search = @study_group.users.search(params[:q])
@members = StudyGroupMembership.where(user: @search.result)
end
def update
myparams = study_group_params
myparams[:users] = StudyGroupMembership.find(myparams[:study_group_membership_ids].reject(&:empty?)).map(&:user)
myparams.delete(:study_group_membership_ids)
update_and_respond(object: @study_group, params: myparams)
end
def destroy
destroy_and_respond(object: @study_group)
end
def study_group_params
params[:study_group].permit(:id, :name, :study_group_membership_ids => []) if params[:study_group].present?
end
private :study_group_params
def set_group
@study_group = StudyGroup.find(params[:id])
authorize!
end
private :set_group
def authorize!
authorize(@study_groups || @study_group)
end
private :authorize!
end