Doug Thompson
Doug Thompson

Reputation: 635

Using ActiveAdmin's DSL with shared module includes

I'm trying to make some common/shared actions for my models registered with ActiveAdmin. I have the following code:

# app/admin/concerns/activatable.rb

module Activatable
  def self.included(dsl)
    dsl.member_action :deactivate, method: :put do
      dsl.resource.deactivate!
      redirect_to dsl.resource_path, notice: 'Deactivated.'
    end
  end
end

# app/admin/course.rb

ActiveAdmin.register Course do
  include Activatable
  # ...
end

When I run rails server, the server immediately quits having thrown the following:

/Users/Doug/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.1/lib/active_record/
dynamic_matchers.rb:26:in `method_missing': undefined method `member_action' for
#<Class:0x00000101e79850> (NoMethodError)

The DSL doesn't appear to have the same functionality as within my course.rb, where the code from activatable.rb works fine (albeit without the dsl.*). Any ideas?

Upvotes: 3

Views: 1929

Answers (1)

Doug Thompson
Doug Thompson

Reputation: 635

I've solved the problem- I had a concern of the same name in my app/models/concerns, and Rails appeared to be muddling these. I renamed my shared ActiveAdmin module to AdminActivatable, and I can now access the DSL object.

Upvotes: 2

Related Questions