base.rb revision 068c4812bb4a75942b62c2124ca1875525b3ac5c
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa#
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa# Base-Controller for editing a permission list
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa# Please subclass this controller for your implementation
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa#
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksaclass PrivilegeList::Base < InheritedResources::Base
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa actions :index, :create, :update, :destroy
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa respond_to :json, :xml
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa rescue_from Permission::PowerVaccuumError, :with => :power_error
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa before_filter :authorize_parent
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa def create
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa build_resource.creator = current_user
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa build_resource.save!
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa respond_to do |format|
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa format.html { render_resource }
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa end
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa end
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa def update
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa resource.update_attributes! *resource_params
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa respond_to do |format|
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa format.html { render_resource }
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa end
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa end
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa def destroy
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa resource.destroy
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa head :ok
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa end
24ddae1e991141fca77d3703fbce61f6f6b0b8e1Eugen Kuksa
protected
def authorize_parent
raise NotImplementedError
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