2012-11-19 155 views
0

當我點擊「創建參與者」按鈕時,出現奇怪的奇怪路由錯誤。很明顯,我誤解了一些關於潰敗的方法。如果你能澄清,將不勝感激!複雜的軌道3嵌套路線

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) %> 

這裏的生成的網址d:

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 

最後這裏是從耙路輸出全:

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 
+0

請問您可以添加路線文件的相關行 –

+0

您正在調用'new_program_patricipant_path',它將使用新方法(而不是您在問題中顯示的索引方法)。你可以顯示你的'ParticipantsController'新方法嗎?該錯誤消息正在查看完全不同的控制器和操作,這使我認爲新方法在其中有重定向? – joofsh

+0

@joofsh:我在上面添加了一些信息,包括整個routes.rb文件。也許你可以看到我不理解的東西?謝謝! – pitosalas

回答

1

路由正在尋找映射到ParticipantsController中的方法的action「present_survey」。 沒有路由匹配{:動作=>「present_survey」 ......}

有一個在ParticipantsController沒有名爲present_survey方法

運行命令「耙路線」讓所有的航線,以列表。

您的網址正在尋找ParticipantsController的新方法,您有嗎?

new_program_participant GET /programs/:program_id/participants/new(.:format)參與者#新

0

感謝@joofsh我想通了,我的問題。事實上,「新的參與者」的形式通過ParticipantController新方法推出包括:

link_to("Current survey form", program_participant_round_survey_path(prog, part.guid, round)) 

和新參與者的part.guid爲零。

課程:當您要求Rails爲您生成路徑時,您不僅可以從字面上調度路由,還可以獲得路由錯誤。