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/ruby-1.9.3-p194@repeatsurvey/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

这是相关的 rake routes 行:

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

我有一个控制器动作 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 %>

谢谢!

4

1 回答 1

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)

当然,变量名称等可能会略有不同,具体取决于您在控制器中定义它们的方式。

于 2012-11-08T13:50:28.000 回答