lib/strong_permitter/manager.rb in strong-permitter-0.0.2 vs lib/strong_permitter/manager.rb in strong-permitter-0.0.3
- old
+ new
@@ -1,13 +1,15 @@
module StrongPermitter
module Manager
def permitted_params
- permission_class = "#{self.class.name.sub('Controller', '')}Permission".camelcase.safe_constantize
- return nil unless permission_class
+ @permission_class ||= "#{self.class.name.sub('Controller', '')}Permission".camelcase.safe_constantize
+ return nil unless @permission_class
- resource_name = permission_class.resource_name || controller_name.singularize
- allowed_attributes = permission_class.actions[action_name]
+ action_hash = @permission_class.actions[action_name.to_sym]
- params.require(resource_name).permit(allowed_attributes)
+ resource_name = action_hash[:resource] || @permission_class.resource_name || controller_name.singularize
+ allowed_params = action_hash[:permitted_params]
+
+ params.required(resource_name).permit(*allowed_params)
end
end
end
\ No newline at end of file