1

I get this error:

Started POST "/admin/reports/2/backfill" for 127.0.0.1 at Thu Dec 29 16:09:00 -0500 2011

ActionController::RoutingError (No route matches "/admin/reports/2/backfill"):

when I post this form:

<%=form_for @report, {:url => report_backfill_path(@report.id), :method => :post} do |f| %>
    <%=label_tag(:days, "number of days to backfill")%>
    <%=select_tag(:days, options_for_select((1..100).to_a.map{|i| [i,i]}))%>
    <%=f.submit "backfill!" %>
<% end %>

but the route is defined, check out the output from my rake routes command:

report_backfill POST   /admin/reports/:report_id/backfill(.:format)    {:controller=>"reports", :action=>"backfill"}

The page containing this form renders fine, it's just when I post it that I get the error.

Any ideas?

7
  • Is it post or put? That's my most common error...
    – DGM
    Dec 29, 2011 at 21:20
  • it is a post, I double checked that a couple of times. Dec 29, 2011 at 21:20
  • looks like I have to use form_tag instead of form_for because I'm not posting to one of the standard routes (nor including the standard object fields). Doesn't make any sense, the form renders pretty much the same. Dec 29, 2011 at 21:27
  • Could you add in the relevant lines from routes.rb ...
    – Tigraine
    Dec 29, 2011 at 21:43
  • Does the generated HTML include the hidden input tag that rails uses to support methods such as PUT ? Dec 29, 2011 at 22:35

1 Answer 1

0

Because you use form_for @report and @report is an existing model, it generates the PUT helpers in the hidden fields, which makes the route engine think it is a PUT request.

Actually, to follow the rails conventions, since you are calling an extra method on the existing report (even though the side effect may be to create things), I would change the routing to use :put instead of :post, and leave the form alone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.