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