3

如何引用当前正在查看的对象的实例?ActiveAdmin - 如何引用当前对象?

WORKS

ActiveAdmin.register Example do 

    sidebar "test" do 
    @name = example.name 
    end 

end 

以下不起作用

ActiveAdmin.register Example do 

    member_action :some_stuff, :method => :put do 
    @name = example.name 
    end 

end 

下我如何引用对象在member_action?或者我会不得不创建另一个实例?

回答

4

大多数活动管理文档已过时或完全不存在。如果您想要了解如何使用它,您可能需要阅读源代码并希望有人评论函数。

member_action function documentation如下:

# Member Actions give you the functionality of defining both the 
# action and the route directly from your ActiveAdmin registration 
# block. 
# 
# For example: 
# 
# ActiveAdmin.register Post do 
#  member_action :comments do 
#  @post = Post.find(params[:id] 
#  @comments = @post.comments 
#  end 
# end 
# 
# Will create a new controller action comments and will hook it up to 
# the named route (comments_admin_post_path) /admin/posts/:id/comments 
# 
# You can treat everything within the block as a standard Rails controller 
# action. 
# 

这使它看起来像他们希望你能在自定义操作执行自己的对象查找 - Post.find(params[:id])

1

您可以使用'资源'对象。

ActiveAdmin.register Example do 

    member_action :some_stuff, :method => :put do 
    @name = resource.name 
    end 

end