Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ActiveAdmin——如何引用当前对象?_Ruby On Rails_Ruby On Rails 3_Ruby On Rails 3.1_Activeadmin - Fatal编程技术网

Ruby on rails ActiveAdmin——如何引用当前对象?

Ruby on rails ActiveAdmin——如何引用当前对象?,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.1,activeadmin,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 3.1,Activeadmin,如何引用当前正在查看的对象的实例 以下有效 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_

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

以下有效

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_操作中引用对象


或者我必须创建另一个实例吗?

大多数活动管理文档都已过时或完全不存在。如果你想知道如何使用它的细节,你可能需要阅读源代码并希望有人对函数进行评论

详情如下:

# 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])

您可以使用“资源”对象

ActiveAdmin.register Example do

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

end