为什么不命名:属性使其成为params内的#destroy动作?

时间:2017-02-16 05:21:18

标签: ruby-on-rails forms ruby-on-rails-4 parameters

我有app/views/shared/stage_items/_destroy.html.erb部分,如下所示:

<%= link_to 'Remove', stage_item_path(stage_item), name: "request_origin[#{controller.controller_name}]", method: :delete %>

当它遇到"request_origin"动作时,我期待在参数中找到StageItems#destroy。我在那里binding.pry设置p params,但它不在那里:

[2] pry(#<StageItemsController>)> pp params
{"_method"=>"delete",
 "authenticity_token"=>
  "1UaOESQFsvDwkZ5QQReS91UVmacmM8FpsV5O+mSoEwPRiS2JvfTNPCLDJlPSjo1XLwSGR5gWtj9IqoNIAp/Z9A==",
 "controller"=>"stage_items",
 "action"=>"destroy",
 "id"=>"8"}

我查看了渲染的html,name属性在那里:

<a name="request_origin[stage_batches]" rel="nofollow" data-method="delete" href="/stage_items/8">Remove</a>

为什么"request_origin" #destroy进入params内的func listNodeAt(_ n: Int) -> [T] { return getElementsAt(n, node: self) } private func getElementsAt(_ n: Int, node: BinaryTreeNode<T>, traversingDepth: Int = 0) -> [T] { var array = Array<T>() if traversingDepth < n { if let left = node.leftChild { array = array + getElementsAt(n, node: left, traversingDepth: traversingDepth + 1) } if let right = node.rightChild { array = array + getElementsAt(n, node: right, traversingDepth: traversingDepth + 1) } } else if traversingDepth == n { array.append(node.value) } return array } 行动?

1 个答案:

答案 0 :(得分:2)

你可以通过在路径中传递来获得额外的参数:

<%= link_to 'Remove', stage_item_path(:id => stage_item.id, :name => "request_origin[#{controller.controller_name}]"), method: :delete %>