Rails:如何使用polymorphic_path动态创建单个嵌套资源的路径

时间:2017-03-23 11:11:17

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

我有一些单一的嵌套资源,它们的条目如下所示:

resources :rocs, only: [:show] do
  resource :r1_response, :r2_response, :r3_response, :r4_response :r5_response do
    member do
      get :print
    end
  end
end

现在我想为我的嵌套奇异资源动态生成路径,如下所示:

print_roc_r1_response_path
print_roc_r2_response_path
...

我正在尝试使用polymorphic_path生成以上路径:

link_to "Print ROC", polymorphic_path([:print, @roc, controller.controller_name])

但是它给出了错误:undefined method print_roc_r1_responses_path因为controller.controller_name复数。我该如何解决?

1 个答案:

答案 0 :(得分:0)

resources :rocs, only: [:show] do
  resources :r1_response, :r2_response, :r3_response, :r4_response :r5_response do
    member do
      get :print
    end
  end
end

将资源更改为资源