内部app / views / participant / 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 %>
但请注意,控制器和路由属于程序模型(出于良好的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
有人看到了吗?谢谢!
答案 0 :(得分: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 %>