nicolas nicolas - 8 months ago 46
Ruby Question

activeadmin : wrong number of arguments (0 for 1) on member_action

i'm building my RoR app admin interface using active admin, got an exception i'm stuck on trying to set up custom actions :

ActiveAdmin.register Deal do
[:cancel, :release].each do |event|
member_action event , method: :patch do |deal|
deal.send :"#{event}!"
redirect_to admin_deal_path(deal), notice: "Your event was #{deal.current_state}"

action_item event, only: :show do
link_to event, url_for(action: event), method: :patch

The event links display well on the page but when clicking on one of them got the following exception :

ArgumentError (wrong number of arguments (0 for 1)):
app/admin/deal.rb:45:in `block (3 levels) in <top (required)>'
app/admin/deal.rb:45:in `block (3 levels) in <top (required)>'

actionpack (4.2.6) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.6) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.6) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.6) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.6) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.6) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.6) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.6) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.6) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.6) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
activesupport (4.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.6) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.6) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.6) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.6) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.6) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.6) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.6) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.6) lib/action_view/rendering.rb:30:in `process'

Line 46 of
is the line where
is called, it seems the
method is overided somehow somewhere or there is something else obvious i don't see...

Any idea where it could come from ? amon other gems I'm using cancancan, devise, and responders.

Thanks in advance

**UPDATED : full stacktrace **

Answer Source

My mistake was to pass a variable to the member_action block, the instance seems to be available via the resource helper

member_action :cancel, method: :patch do
  redirect_to admin_deal_path(resource)