Permalink
Browse files

#1731 removing strong_parameters config option and changed to permit_…

…all in controller
  • Loading branch information...
1 parent 004764e commit ccf2cbd03edf88486e04d19835ba045f6d4c89e9 @garysweaver committed Oct 19, 2012
View
@@ -84,7 +84,7 @@ when trying to view the dashboard (at +/admin+), ensure +app/admin/dashboards.rb
== Strong Parameters
-If you are an early adopter of strong_parameters which will be part of Rails 4, add `config.strong_parameters_permit_all = true` to your configuration and `support_strong_parameters` to your controller definition.
+If you are an early adopter of strong_parameters which will be part of Rails 4 and wish to permit all attributes, you may choose to add `permit_all` to your controller definition to permit all attributes.
== Next Steps
@@ -69,9 +69,6 @@ def self.inheritable_setting(name, default)
# Default CSV separator
inheritable_setting :csv_column_separator, ','
- # Strong Parameters patch behavior
- inheritable_setting :strong_parameters_permit_all, false
-
# Active Admin makes educated guesses when displaying objects, this is
# the list of methods it tries calling in order
setting :display_name_methods, [ :display_name,
View
@@ -15,7 +15,7 @@ def initialize(config)
#TODO: replace this temporary hack for strong_parameters, part of Rails 4.0 support
# include patch provided by dpmccabe in https://gist.github.com/3718571
- def support_strong_parameters
+ def permit_all
@config.controller.class_eval("include ActiveAdmin::StrongParametersPatch")
end
@@ -8,17 +8,15 @@ module StrongParametersPatch
extend ActiveSupport::Concern
def initialize
- @instance_name = active_admin_config.resource_name.gsub(/(.)([A-Z])/,'\1_\2').downcase
+ @instance_name = active_admin_config.resource_class.name.underscore.to_sym
@klass = active_admin_config.resource_class
super
end
def create
# TODO: allow controller-specified attribute permits
- instance_param = !!active_admin_config.options.strong_parameters_permit_all ? params[@instance_name.to_sym].permit! : params[@instance_name.to_sym]
-
- resource_obj = instance_variable_set("@#{@instance_name}", @klass.new(instance_param))
+ resource_obj = instance_variable_set("@#{@instance_name}", @klass.new(params[@instance_name].permit!))
if resource_obj.save
redirect_to send("admin_#{@instance_name}_path", resource_obj), notice: "Created #{@instance_name}."
@@ -28,12 +26,10 @@ def create
end
def update
- # TODO: allow controller-specified attribute permits
- instance_param = !!active_admin_config.options.strong_parameters_permit_all ? params[@instance_name.to_sym].permit! : params[@instance_name.to_sym]
-
resource_obj = instance_variable_set("@#{@instance_name}", @klass.find(params[:id]))
-
- if resource_obj.update_attributes(instance_param)
+
+ # TODO: allow controller-specified attribute permits
+ if resource_obj.update_attributes(params[@instance_name].permit!)
redirect_to send("admin_#{@instance_name}_path", resource_obj), notice: "Updated #{@instance_name}."
else
render :edit
@@ -146,10 +146,4 @@ ActiveAdmin.setup do |config|
#
# Set the CSV builder separator (default is ",")
# config.csv_column_separator = ','
-
- # == Strong Parameters options
- #
- # If using support_strong_parameters in your controller, permit all attributes.
- #
- config.strong_parameters_permit_all = true
end

0 comments on commit ccf2cbd

Please sign in to comment.