将参数传递给 Rails 路径助手

Bit*_*ise 1 ruby ruby-on-rails

我正在尝试将参数传递到我的 Rails 路径助手中,但我当前的尝试不起作用。这是我现在正在做的事情:

<%= link_to "Pause Assignment", pause_account_complete_assignment_index_path(@assignment.current_timekeeper) %>
Run Code Online (Sandbox Code Playgroud)

控制器

def pause
  binding.pry
end 
Run Code Online (Sandbox Code Playgroud)

在控制器中,我正在寻找传入的参数。但没有找到它们。这是返回的内容。

<ActionController::Parameters {"controller"=>"accounts/complete_assignment", "action"=>"pause"} permitted: false>
Run Code Online (Sandbox Code Playgroud)

路线

resources :complete_assignment, only: [:create, :destroy] do
  get 'pause', on: :collection
end
Run Code Online (Sandbox Code Playgroud)

这可能与我在集合上使用的事实有关?

但是,基本上我如何传递@assigment.current_timkeeper控制器?

Dee*_*ale 7

您应该以哈希语法传递额外的参数

<%= link_to "Pause Assignment", pause_account_complete_assignment_index_path(current_timekeeper: @assignment.current_timekeeper) %>
Run Code Online (Sandbox Code Playgroud)

这会给你类似的参数

<ActionController::Parameters {
  "controller"=>"accounts/complete_assignment", 
  "action"=>"pause",
  "current_timekeeper"=>"value_of_current_timekeeper" 
 } permitted: false>
Run Code Online (Sandbox Code Playgroud)