ActiveAdmin——如何引用当前对象?

发布于 2024-12-15 00:03:19 字数 402 浏览 2 评论 0原文

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

以下有效

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 中引用该对象?

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

How can you reference the instance of the object you are currently viewing?

The following WORKS

ActiveAdmin.register Example do

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

end

The following DOESN'T Work

ActiveAdmin.register Example do

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

end

How can I reference the object in the member_action?

Or will I have to create another instance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

混浊又暗下来 2024-12-22 00:03:22

您可以使用“资源”对象。

ActiveAdmin.register Example do

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

end

You can use 'resource' object.

ActiveAdmin.register Example do

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

end
酒废 2024-12-22 00:03:22

大多数有效的管理文档已经过时或完全不存在。如果您想了解如何使用它的详细信息,您可能必须阅读源代码并希望有人对函数进行评论。

member_action 函数文档如下所示:

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

Most of the active admin documentation is out of date or completely nonexistent. You will likely have to read the source and hope somebody commented functions if you want the nitty-gritty on how to use it.

The member_action function documentation is as follows:

# 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.
# 

This makes it look like they expect you to perform your own object lookup in custom actions - Post.find(params[:id]).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文