2017-02-16 60 views
0

我有一個app/views/shared/stage_items/_destroy.html.erb部分,看起來像下面這樣:爲什麼不是name:屬性使它成爲Params中的#destroy動作?

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

我期待找到在PARAMS "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

回答

2

你可以通過將其在路徑獲得額外參數:

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