Skip to content

Instantly share code, notes, and snippets.

@atomical
Forked from cjcolvar/controller
Created June 6, 2013 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomical/5722743 to your computer and use it in GitHub Desktop.
Save atomical/5722743 to your computer and use it in GitHub Desktop.
class RolesController < ApplicationController
include Hydra::RoleManagement::RolesBehavior
prepend_before_filter :accept_batches, only: [:destroy]
def destroy
@roles.each {|role| role.destroy}
redirect_to roles_path, notice: "Successfully deleted groups: #{params[:ids].join(", ")}"
end
def accept_batches
if params[:id]
params[:ids] = [params[:id]].flatten
params[:id] = nil
end
params[:ids] ||= []
#This implementation of batch works based upon cancan's returning of all roles when no params[:id] is supplied
#Thus authorize_resource is checking can? :delete, Role instead of can? :delete, 1, can? :delete, 2, etc.
#Or is cancan able to check @roles instead?!?
@roles = Role.where(id: params[:ids])
end
end
resources :roles do
collection do
delete :destroy
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment