lib/controller_resources/extension.rb in controller_resources-0.0.1 vs lib/controller_resources/extension.rb in controller_resources-0.0.2
- old
+ new
@@ -51,10 +51,11 @@
expose :#{model}, except: %w(index)
expose :#{collection}, only: %w(index) do
#{model_class}.where(search_params)
end
#{authenticate if defined? Devise}
+ #{authorize if defined? Authority}
RUBY
yield if block_given?
end
@@ -72,11 +73,19 @@
private
def authenticate
"before_action :authenticate_user!, except: %w(index show)"
end
+ def authorize
+ "authorize_actions_for #{model_class}"
+ end
+
def model_class
- @model_class ||= model.classify
+ @model_class ||= self._singleton_resource.to_s.classify
+ end
+
+ def model
+ self._singleton_resource
end
def collection
@collection ||= self._collection_resource.to_s
end