base.rb revision 7b025f9d9726413eb3f50ca2b39826e7eed816fb
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber#
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber# Base-Controller for editing a permission list
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber# Please subclass this controller for your implementation
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber#
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graberclass PrivilegeList::Base < InheritedResources::Base
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber actions :create, :update, :destroy
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber rescue_from Permission::PowerVaccuumError, :with => :power_error
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber before_filter :authorize_parent
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber def create
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber build_resource.save!
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber respond_to do |format|
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber format.html { render_resource }
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber end
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber end
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber
dc0682900a79cfb47fd9a416902129bfa68fdcbfStéphane Graber def update
5b0e4923bc39cf34215e44fccc425b1f3e42674bAnrDaemon resource.update_attributes! *resource_params
respond_to do |format|
format.html { render_resource }
end
end
def destroy
resource.destroy
head :ok
end
protected
def authorize_parent
authorize! :edit, parent
end
helper_method :permission_list
def permission_list
raise NotImplementedError
# you need to override this method with something like:
# @permission_list ||= PermissionList.new ...
end
def render_resource
render :partial => resource, :locals => {:permission_list => permission_list}
end
def power_error(exception)
render :text => exception.message, :status => :unprocessable_entity
end
end