Using ActiveAdmin's DSL with shared module includes

谁说我不能喝 提交于 2019-12-23 22:37:29

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/24789006/using-activeadmins-dsl-with-shared-module-includes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!