Permalink
Browse files

#1731 using Jasper's changes for strong_parameters patch. readding re…

…moval of id, created_at, updated_at from @columns but using Jasper's changes to permit! without columns specified
  • Loading branch information...
1 parent e14a248 commit fef004e620d8260002ba6e0e9f82384b0cae165e @garysweaver committed Oct 19, 2012
Showing with 14 additions and 8 deletions.
  1. +14 −8 lib/active_admin/strong_parameters_patch.rb
@@ -1,26 +1,32 @@
+# lib/active_admin_extentions/strong_admin.rb
module ActiveAdmin
- # The following contains code provided by dpmccabe in https://gist.github.com/3718571
+ # The following contains code provided by
+ # dpmccabe in https://gist.github.com/3718571
+ # jasperkennis in https://gist.github.com/3907216
module StrongParametersPatch
+
extend ActiveSupport::Concern
def initialize
@instance_name = active_admin_config.resource_name.gsub(/(.)([A-Z])/,'\1_\2').downcase
@klass = active_admin_config.resource_name.constantize
@column_names = @klass.columns.map do |column|
- case column.type
- when :datetime, :date, :time
- ([column.name.to_sym] + (1..5).inject([]) { |acc, x| acc << :"#{column.name}(#{x}i)" })
- else
- column.name.to_sym
+ unless [:id, :created_at, :updated_at].include?(column.name.to_sym)
+ case column.type
+ when :datetime, :date, :time
+ ([column.name.to_sym] + (1..5).inject([]) { |acc, x| acc << :"#{column.name}(#{x}i)" })
+ else
+ column.name.to_sym
+ end
end
end.flatten
super
end
def create
- resource_obj = instance_variable_set("@#{@instance_name}", @klass.new(params[@instance_name.to_sym].permit(*@column_names)))
+ resource_obj = instance_variable_set("@#{@instance_name}", @klass.new(params[@instance_name.to_sym].permit!))
if resource_obj.save
redirect_to send("admin_#{@instance_name}_path", resource_obj), notice: "Created #{@instance_name}."
@@ -32,7 +38,7 @@ def create
def update
resource_obj = instance_variable_set("@#{@instance_name}", @klass.find(params[:id]))
- if resource_obj.update_attributes(params[@instance_name.to_sym].permit(*@column_names))
+ if resource_obj.update_attributes(params[@instance_name.to_sym].permit!)
redirect_to send("admin_#{@instance_name}_path", resource_obj), notice: "Updated #{@instance_name}."
else
render :edit

0 comments on commit fef004e

Please sign in to comment.