路线配置问题

时间:2014-05-21 14:38:45

标签: ruby-on-rails ruby-on-rails-3

我的路线有问题似乎无法弄明白。我很欣赏任何见解。以下是详细信息:

config/routes.rb
resources :expectations do
  resources :expectation_fulfillments do
    collection do
      put :update_expectation_fulfillments
    end
  end
end

rake路线的输出:

update_expectation_fulfillments_expectation_expectation_fulfillments  PUT /expectations/:expectation_id/expectation_fulfillments/update_expectation_fulfillments(.:format) {:action=>"update_expectation_fulfillments", :controller=>"expectation_fulfillments"}

型号:

app/models/expectation.rb
has_many :expectation_fulfillments

app/models/expectation_fulfillment.rb
belongs_to :expectation

控制器:

app/controllers/expectation_fulfillments_controller.rb
def update_expectation_fulfillments
  ExpectationFulfillment.update(params[:expectation_fulfillment].keys, params[:expectation_fulfillment].values)
  redirect_to :action => "index"
end

查看:

<%= form_for :expectation_fulfillment, :url => {:action => "update_expectation_fulfillments"} do %>
<table class="pretty">
  <thead>
    <tr>
      <th>Expected Date</th>
      <th>Actual Date</th>
    </tr>
  </thead>
  <tbody>
    <% @expectation_fulfillments.each do |expectation_fulfillment| %>
      <%= fields_for "expectation_fulfillment[]", expectation_fulfillment do |f| %>
        <tr>
          <td><%= f.datepicker :expected_date, :class => "textInputDate", :value => f.object.expected_date.try('strftime','%m/%d/%Y') %></td>
          <td><%= f.datepicker :actual_date, :class => "textInputDate", :value => f.object.actual_date.try('strftime','%m/%d/%Y') %></td>
        </tr>
      <% end %>
    <% end %>
  </tbody>
</table>
<%= submit_tag "Update" %>
<% end %>

提交该表格后,我收到错误:

Following are details of the error:
Message:Page not found

Stack Trace:
http://server/expectations/31/expectation_fulfillments/update_expectation_fulfillments

我为何感到茫然?有什么想法吗?

编辑: 日志输出:

Started POST "/expectations/31/expectation_fulfillments/update_expectation_fulfillments" for 192.168.124.46 at 2014-05-21 13:20:38 -0400
  Processing by ErrorsController#_404 as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"xx=", "expectation_fulfillment"=>{"17"=>{"expected_date"=>"05/08/2012", "actual_date"=>"11/29/2012", "tapelog_id"=>""}, "25"=>{"expected_date"=>"05/23/2012", "actual_date"=>""}, "26"=>{"expected_date"=>"05/30/2012", "actual_date"=>""}, "27"=>{"expected_date"=>"06/06/2012", "actual_date"=>""}, "28"=>{"expected_date"=>"06/13/2012", "actual_date"=>""}, "29"=>{"expected_date"=>"06/20/2012", "actual_date"=>""}, "30"=>{"expected_date"=>"06/27/2012", "actual_date"=>""}, "31"=>{"expected_date"=>"07/04/2012", "actual_date"=>""}, "32"=>{"expected_date"=>"07/11/2012", "actual_date"=>""}, "33"=>{"expected_date"=>"07/18/2012", "actual_date"=>""}, "34"=>{"expected_date"=>"07/25/2012", "actual_date"=>""}, "35"=>{"expected_date"=>"08/01/2012", "actual_date"=>""}, "36"=>{"expected_date"=>"08/08/2012", "actual_date"=>""}, "37"=>{"expected_date"=>"08/15/2012", "actual_date"=>""}, "143"=>{"expected_date"=>"08/22/2012", "actual_date"=>""}, "144"=>{"expected_date"=>"08/29/2012", "actual_date"=>""}, "145"=>{"expected_date"=>"09/05/2012", "actual_date"=>""}, "146"=>{"expected_date"=>"09/12/2012", "actual_date"=>""}, "160"=>{"expected_date"=>"11/28/2012", "actual_date"=>""}, "161"=>{"expected_date"=>"12/05/2012", "actual_date"=>""}, "162"=>{"expected_date"=>"12/12/2012", "actual_date"=>"", "tapelog_id"=>""}, "163"=>{"expected_date"=>"12/19/2012", "actual_date"=>"", "tapelog_id"=>""}, "164"=>{"expected_date"=>"12/26/2012", "actual_date"=>""}, "165"=>{"expected_date"=>"01/02/2013", "actual_date"=>""}, "166"=>{"expected_date"=>"01/09/2013", "actual_date"=>""}, "167"=>{"expected_date"=>"01/16/2013", "actual_date"=>""}, "168"=>{"expected_date"=>"01/23/2013", "actual_date"=>""}, "169"=>{"expected_date"=>"01/30/2013", "actual_date"=>""}, "170"=>{"expected_date"=>"02/06/2013", "actual_date"=>""}, "171"=>{"expected_date"=>"02/13/2013", "actual_date"=>""}}, "commit"=>"Update", "a"=>"expectations/31/expectation_fulfillments/update_expectation_fulfillments"}

1 个答案:

答案 0 :(得分:0)

您的服务器告诉您正在发布POST。 但是你应该进行更新。

<%= form_for :expectation_fulfillment, :method => :update, :url => {:action => "update_expectation_fulfillments"} do %>