Class: Admin::GroupsController
- Inherits:
-
ResourceController
- Object
- ResourceController
- Admin::GroupsController
- Defined in:
- app/controllers/admin/groups_controller.rb
Instance Method Summary collapse
Instance Method Details
#add_member ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/admin/groups_controller.rb', line 28 def add_member if request.post? @group = Group.find params[:id] @user = User.find params[:user_id] @group.users << @user @group.save flash[:notice] = "#{@user.name} added to #{@group.name}." end rescue ::ActiveRecord::RecordNotFound if @group.nil? flash[:error] = "Group not found for that id." elsif @user.nil? flash[:error] = "Please select a user to add to #{@group.name}." end ensure redirect_to admin_groups_url end |
#add_page ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/admin/groups_controller.rb', line 9 def add_page page = Page.find params[:page_id] begin group = Group.find params[:group_id] page.group = group page.save flash[:notice] = "Group for \"#{page.title}\" set to #{group.name}." rescue ::ActiveRecord::RecordNotFound page.group = nil page.save flash[:notice] = "Group removed from \"#{page.title}\"." ensure redirect_to :controller => 'admin/page', :action => 'index' end end |
#remove_member ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/admin/groups_controller.rb', line 47 def remove_member @group = Group.find params[:group_id] @user = User.find params[:id] if request.delete? @group.users.delete @user @group.save flash[:notice] = "#{@user.name} removed from #{@group.name}." redirect_to admin_groups_url end rescue if @group.nil? flash[:error] = "Group not found for that group id." elsif @user.nil? flash[:error] = "User not found for that user id." end redirect_to admin_groups_url end |