简体   繁体   English

将参数传递到Rails路径助手中

[英]Pass params into rails path helper

I'm trying to pass params into my rails path helper but my current attempt is not working. 我正在尝试将参数传递到我的Rails路径帮助器中,但是我当前的尝试不起作用。 Here is what I'm doing now: 这是我现在正在做的事情:

<%= link_to "Pause Assignment", pause_account_complete_assignment_index_path(@assignment.current_timekeeper) %>

Controller 控制者

def pause
  binding.pry
end 

In the controller I'm looking for the params I passed in. But they are not found. 在控制器中,我正在寻找传入的参数。但是找不到它们。 Here is what is returned. 这是返回的内容。

<ActionController::Parameters {"controller"=>"accounts/complete_assignment", "action"=>"pause"} permitted: false>

routes 路线

resources :complete_assignment, only: [:create, :destroy] do
  get 'pause', on: :collection
end

It may have something to do with the fact I using on collection? 这可能与我在收藏中使用的事实有关吗?

But, basically how do I pass @assigment.current_timkeeper in the controller? 但是,基本上我该如何在控制器中传递@assigment.current_timkeeper

You should pass the extra params in hash syntax 您应该在哈希语法中传递额外的参数

<%= link_to "Pause Assignment", pause_account_complete_assignment_index_path(current_timekeeper: @assignment.current_timekeeper) %>

This will give you params like 这会给你像

<ActionController::Parameters {
  "controller"=>"accounts/complete_assignment", 
  "action"=>"pause",
  "current_timekeeper"=>"value_of_current_timekeeper" 
 } permitted: false>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM