当我单击“创建参与者”按钮时,我收到了这个奇怪的路由错误。显然,我误解了溃败的工作原理。如果您能澄清一下,将不胜感激!
No route matches {:action=>"present_survey", :controller=>"rounds", :program_id=>#
<Program id: 1, name: "JBS 2012", description: "Summer of 2012", open: false,
locked: true, suppress_hidden_participants: false, created_at: "2012-11-19 22:35:06",
updated_at: "2012-11-19 22:35:06">, :participant_id=>nil, :round_id=>#<Round id: 9,
program_id: 1, number: 8, start: 86, fin: 95, status: nil, open: true, open_date: nil,
created_at: "2012-11-19 22:35:07", updated_at: "2012-11-19 22:35:07">}
这是相关的 routes.rb 行:
new_program_participant GET /programs/:program_id/participants/new(.:format) participants#new
以下是相关的控制器行:
class ParticipantsController < ApplicationController
respond_to :html
def index
@program_id = params[:program_id]
@program = Program.find(@program_id)
@participants = @program.participants.paginate(page: params[:page])
respond_with @participants do |format|
format.html {
render layout: 'layouts/progtabs'
}
end
end
这是相关的视图行:
<%= link_to "Create a new Participant", new_program_participant_path(@program_id) %>
这是生成的网址:
http://0.0.0.0:3000/programs/1/participants/new
由原始海报编辑:
针对以下问题和评论:
- 该链接出现在索引页面上,应该将我带到指定的 URL,因此该链接对我来说似乎是正确的。
- 您可以在下面的 routes.rb 中看到,确实我有一个名为 present_survey 的操作,但我不明白为什么它在起作用
这是整个路线文件:
root to: 'programs#index'
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'
end
end
最后是 rake 路由的完整输出:
root / programs#index
program_participant_round_survey GET /programs/:program_id/participants/:participant_id/rounds/:round_id/survey(.:format) rounds#present_survey
PUT /programs/:program_id/participants/:participant_id/rounds/:round_id/survey(.:format) rounds#store_survey
program_participant_rounds GET /programs/:program_id/participants/:participant_id/rounds(.:format) rounds#index
POST /programs/:program_id/participants/:participant_id/rounds(.:format) rounds#create
new_program_participant_round GET /programs/:program_id/participants/:participant_id/rounds/new(.:format) rounds#new
edit_program_participant_round GET /programs/:program_id/participants/:participant_id/rounds/:id/edit(.:format) rounds#edit
program_participant_round GET /programs/:program_id/participants/:participant_id/rounds/:id(.:format) rounds#show
PUT /programs/:program_id/participants/:participant_id/rounds/:id(.:format) rounds#update
DELETE /programs/:program_id/participants/:participant_id/rounds/:id(.:format) rounds#destroy
program_participants GET /programs/:program_id/participants(.:format) participants#index
POST /programs/:program_id/participants(.:format) participants#create
new_program_participant GET /programs/:program_id/participants/new(.:format) participants#new
edit_program_participant GET /programs/:program_id/participants/:id/edit(.:format) participants#edit
program_participant GET /programs/:program_id/participants/:id(.:format) participants#show
PUT /programs/:program_id/participants/:id(.:format) participants#update
DELETE /programs/:program_id/participants/:id(.:format) participants#destroy
program_questions GET /programs/:program_id/questions(.:format) questions#index
POST /programs/:program_id/questions(.:format) questions#create
new_program_question GET /programs/:program_id/questions/new(.:format) questions#new
edit_program_question GET /programs/:program_id/questions/:id/edit(.:format) questions#edit
program_question GET /programs/:program_id/questions/:id(.:format) questions#show
PUT /programs/:program_id/questions/:id(.:format) questions#update
DELETE /programs/:program_id/questions/:id(.:format) questions#destroy
program_rounds GET /programs/:program_id/rounds(.:format) rounds#index
POST /programs/:program_id/rounds(.:format) rounds#create
new_program_round GET /programs/:program_id/rounds/new(.:format) rounds#new
edit_program_round GET /programs/:program_id/rounds/:id/edit(.:format) rounds#edit
program_round GET /programs/:program_id/rounds/:id(.:format) rounds#show
PUT /programs/:program_id/rounds/:id(.:format) rounds#update
DELETE /programs/:program_id/rounds/:id(.:format) rounds#destroy
report_program GET /programs/:id/report(.:format) reports#report
programs GET /programs(.:format) programs#index
POST /programs(.:format) programs#create
new_program GET /programs/new(.:format) programs#new
edit_program GET /programs/:id/edit(.:format) programs#edit
program GET /programs/:id(.:format) programs#show
PUT /programs/:id(.:format) programs#update
DELETE /programs/:id(.:format) programs#destroy
OP的更多编辑
def new
@program = Program.find(params[:program_id])
@participant = @program.participants.new
respond_with @participant do |format|
format.html {
render layout: 'layouts/progtabs'
}
end
end