0

在 app/views/participants/index.html.erb 内部:

<%= form_tag bulk_add_participants_program_path do %>
  <%= wrap_control_group do %>
    <%= text_area_tag :bulk_add_participants, :size => "60x3" %>
    <% end %>
    <%= submit_tag "Import Participants and Users" %>
<% end %>

但请注意,控制器和路由与 Program 模型相关(出于良好的 UI 原因)。我认为这可能与问题有关。当我渲染该视图时,我收到此错误消息:

No route matches {:action=>"bulk_add_participants", :controller=>"programs"}

这很奇怪,因为在 app/controllers/programs_controller.rb 中:

  def bulk_add_participants
    puts "yay!"  # because i am troubleshooting
  end

我的 config/Routes.rb 是:

RepSurv::Application.routes.draw do

  root to: 'programs#index'

  devise_for :users, path_prefix: 'devise'
  resources :users

  resources :programs do
    resources :participants do
      resources :rounds do
        get 'survey' => 'rounds#present_survey'
        put 'survey' => 'rounds#store_survey'
      end
    end
    resources :questions
    resources :rounds
    member do
      get 'report' => 'reports#report'
      get 'bulk_add_participants'
    end
  end
end
4

1 回答 1

2

它没有找到路线,因为您已将programs其定义为复数资源:

resources :programs do

当您这样做并引用member您的路线bulk_add_participants时,它需要:program_id您的情况下的参数。(尝试运行rake routes,你会看到类似的路径/programs/:program_id/bulk_add_participants。)

所以你的form_tag电话应该是这样的:

<%= form_tag bulk_add_participants_program_path(@program) do %>
于 2013-02-26T21:39:25.150 回答