通过共享模块使用ActiveAdmin的DSL,包括 [英] Using ActiveAdmin's DSL with shared module includes
问题描述
我正在尝试对在ActiveAdmin中注册的模型进行一些常见/共享的操作。我有以下代码:
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
当我运行 rails服务器
时,服务器会抛出以下内容立即退出:
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)
DSL似乎不具有与我的<$ c $相同的功能c> course.rb ,其中 activatable.rb
中的代码可以正常工作(尽管没有 dsl。*
)。有什么想法吗?
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?
推荐答案
我已经解决了这个问题-我在 app / models / concerns
,而Rails似乎混淆了这些。我将共享的ActiveAdmin模块重命名为 AdminActivatable
,现在可以访问DSL对象。
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.
这篇关于通过共享模块使用ActiveAdmin的DSL,包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!