lib/governor/controllers/helpers.rb in governor-0.1.1 vs lib/governor/controllers/helpers.rb in governor-0.2.0

- old
+ new

@@ -1,20 +1,8 @@ module Governor module Controllers module Helpers - def resources_url - url_for :controller => mapping.controller, :governor_mapping => params[:governor_mapping], :action => 'index' - end - - def new_resource_url - url_for :controller => mapping.controller, :governor_mapping => params[:governor_mapping], :action => 'new' - end - - def edit_resource_url(resource) - url_for :controller => mapping.controller, :governor_mapping => params[:governor_mapping], :action => 'edit', :id => resource.id - end - def resource instance_variable_get("@#{mapping.singular}") end def resource_sym @@ -41,22 +29,30 @@ def mapping Governor.resources[params[:governor_mapping]] end def init_resource - set_resource model_class.find(params[:id]) + set_resource model_class.find(params["#{mapping.singular}_id"] || params[:id]) end + + def the_governor + instance_eval(&Governor.author) + end + + def governor_logged_in? + the_governor.present? + end def authorize_governor! if defined?(resource) redirect_to root_path unless governor_authorized?(action_name, resource) else - send("authenticate_#{Devise.default_scope}!") unless governor_authorized?(action_name) + instance_eval(&Governor.if_not_allowed) unless governor_authorized?(action_name) end end def governor_authorized?(action, article=nil) - Governor.authorized?(self, action, article) + instance_exec(action, article, &Governor.authorization_rules) end end end end \ No newline at end of file