2012-11-08 48 views
0

當我刷新頁面我得到這個錯誤信息:路徑規格似乎並不匹配生成的方法

ActionController::RoutingError (No route matches {:action=>"value", :controller=>"round"}): 
    app/views/surveys/survey.html.erb:28:in `block in _app_views_surveys_survey_html_erb___3955880096442191391_70175035205180' 
    app/views/surveys/survey.html.erb:22:in `_app_views_surveys_survey_html_erb___3955880096442191391_70175035205180' 
    app/controllers/surveys_controller.rb:16:in `block (2 levels) in survey' 
    app/controllers/surveys_controller.rb:14:in `survey'  
    Rendered /Users/pitosalas/.rvm/gems/[email protected]/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.5ms) 

我感到很困惑這個。爲什麼引用program_participant_round_value_path引起該路線丟失?

這是我的路線文件:

root to: 'programs#index' 
    resources :programs do 
    resources :participants do 
     get 'survey' => 'surveys#survey' 
    end 
    resources :questions 
    resources :rounds 
    member do 
     get 'report' => 'reports#report' 
    end 
    end 
    resources :program do 
    resources :participant do 
     resources :round do 
     put :value 
     end 
    end 
    end 

而這裏的相關耙路線:

program_participant_round_value PUT /program/:program_id/participant/:participant_id/round/:round_id/value(.:format) round#value 

我有一個控制器動作回合#值。

這裏的視圖的相關部分:

<%= content_tag :table do %> 
    <%= content_tag :thead do %> 
    <% 5.times do |q| %> 
     <%= content_tag :th, "1" %> 
    <% end %> 
    <% end %> 
    <% form_tag program_participant_round_value_path do %> 
    <%= content_tag :tbody do %> 
     <%= render partial: 'surveys/value', collection: @values %> 
    <% end %> 
    <%= submit_tag "Save" %> 
    <% end %> 
<% end %> 

謝謝!

回答

1

program_participant_round_value航線期待幾個參數:

  • :program_id
  • :participant_id
  • :round_id

您需要爲那些當你調用program_participant_round_value_path輔助參數提供值:

program_participant_round_value_path(program_id: @program, participant_id: @participant, round_id: @round) 

當然,根據您在控制器中定義它們的方式,變量名稱等可能會略有不同。

+0

而這會影響它尋找的路線?奇。讓我嘗試。謝謝! – pitosalas

+0

好的進展,但現在我得到的錯誤:沒有路由匹配{:action =>「value」,:controller =>「round」,:program => 1,:participant => 2,:round => 9}我需要對路線進行一些更改。但在我走下這條路之前,我寧願提交表單的網址看起來像./program/1/participant/2/round/3/update。你似乎知道這個東西很冷。你能給我一個指針嗎?謝謝10^6 – pitosalas

+0

一定要將'method::put'作爲參數傳遞給'form_tag'。 –

相關問題