Skip to content

Commit

Permalink
fix permit_params for renamed resources
Browse files Browse the repository at this point in the history
specifically, this fixes the tests for AA::Comment
  • Loading branch information
seanlinsley committed May 17, 2014
1 parent ebcde7b commit 8872d84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 10 additions & 0 deletions lib/active_admin/resource/naming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def resource_label
def plural_resource_label(options = {})
resource_name.translate ({count: ::ActiveAdmin::Helpers::I18n::PLURAL_MANY_COUNT, default: resource_label.pluralize.titleize}).merge(options)
end

# Helper method for forms. Forms still use a model's param_key, even if
# the model has been renamed, so we can't use our custom `resource_name` above.
def param_key
if resource_class.respond_to? :model_name
resource_class.model_name.param_key
else
resource_name.param_key
end
end
end

# A subclass of ActiveModel::Name which supports the different APIs presented
Expand Down
5 changes: 2 additions & 3 deletions lib/active_admin/resource_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ def scope(*args, &block)
# end
#
def permit_params(*args, &block)
resource_sym = config.resource_name.singular.to_sym
param_key = config.param_key.to_sym

controller do
define_method :permitted_params do
params.permit resource_sym =>
block ? instance_exec(&block) : args
params.permit param_key => block ? instance_exec(&block) : args
end
end
end
Expand Down

0 comments on commit 8872d84

Please sign in to comment.