railsactiveadmin如何使用action_item?
rails activeadmin how to use action_item?
糟糕的文档说:
action_item :view, only: :show do
link_to 'View on site', post_path(post) if post.published?
end
但它并没有说明 post_path(post) 中的 "post" 来自哪里。
我想在这个例子中他们正在添加一个 'view' 自定义操作,它将在保存 class 中执行视图 member_action,并且所有这些仅存在于显示(详细资源显示)。 member_action 方法需要资源的 id(作为 params[:id] 传递)。首先,我认为文档中有错误,应该是 view_post_path(...)。现在,这个未记录的 "post" 变量来自哪里?
member_action 示例中还有另一个未记录的谜团:
member_action :lock, method: :put do
resource.lock!
redirect_to resource_path, notice: "Locked!"
end
什么是 "resource"?
另一个问题:
如何覆盖编辑、销毁等现有操作?
如果 activeadmin 不是 ~95% 未记录它可能非常有用。
您需要注意 ActiveAdmin 建立在其他 gem 之上,包括 Rails 和继承资源。如果您熟悉 Rails(我不建议 Rails 初学者使用 AA),那么您可能会认为 post_path 是一个自动生成的 URL 助手,returns 一个 link 到一个假设的 post 模型。这是开源的,您可以阅读 specs for action item on GitHub,在那里您会看到正在注册的 Post 资源,这可能是 Sean 在自愿编写此文档时的想法。
resource
来自 Inherited Resources gem,您将在其 README.
中找到有关覆盖编辑、销毁等的文档
我认为documentation of action_item is reasonable, if terse, and you appear to have understood most of it. If you think the documentation has an error or wish to help improve it you are welcome to volunteer a pull request. There are also various other tutorials, example apps and blog posts you may find helpful linked to from the wiki。
糟糕的文档说:
action_item :view, only: :show do
link_to 'View on site', post_path(post) if post.published?
end
但它并没有说明 post_path(post) 中的 "post" 来自哪里。 我想在这个例子中他们正在添加一个 'view' 自定义操作,它将在保存 class 中执行视图 member_action,并且所有这些仅存在于显示(详细资源显示)。 member_action 方法需要资源的 id(作为 params[:id] 传递)。首先,我认为文档中有错误,应该是 view_post_path(...)。现在,这个未记录的 "post" 变量来自哪里?
member_action 示例中还有另一个未记录的谜团:
member_action :lock, method: :put do
resource.lock!
redirect_to resource_path, notice: "Locked!"
end
什么是 "resource"?
另一个问题:
如何覆盖编辑、销毁等现有操作?
如果 activeadmin 不是 ~95% 未记录它可能非常有用。
您需要注意 ActiveAdmin 建立在其他 gem 之上,包括 Rails 和继承资源。如果您熟悉 Rails(我不建议 Rails 初学者使用 AA),那么您可能会认为 post_path 是一个自动生成的 URL 助手,returns 一个 link 到一个假设的 post 模型。这是开源的,您可以阅读 specs for action item on GitHub,在那里您会看到正在注册的 Post 资源,这可能是 Sean 在自愿编写此文档时的想法。
resource
来自 Inherited Resources gem,您将在其 README.
我认为documentation of action_item is reasonable, if terse, and you appear to have understood most of it. If you think the documentation has an error or wish to help improve it you are welcome to volunteer a pull request. There are also various other tutorials, example apps and blog posts you may find helpful linked to from the wiki。