Reputation: 4047
Something very funny is happening... my controller has two checks that are made separately before it allows the form to be submitted (the code below is simplistic, there are other things happening). If either checkpoint fails, the new
page is re-rendered.
Here's the code:
def create
if checkpointone == fail
render 'new'
else
if checkpointtwo == fail
render 'new'
else
redirect_to action: 'success'
end
end
end
Here's the funny flow problem I'm running into:
checkpointone
and passes checkpointtwo
new
page successfully re-rendered with original parameters and error messagecheckpointone
fails again, or it passes but checkpointtwo
fails)No route matches [PATCH] "/requests"
But why on earth is it looking for a PATCH all of the sudden? Who told it to? The weird thing is that if I start with a fail in checkpointtwo
and a pass in checkpointone
, from then on, I can make any number of fails and resubmissions in various combinations, and I'll always get the correct action: new
page re-rendered with original parameters and error message.
Snippet of view code:
<%= form_for @requestrecord, :url => { action: 'create' }, :html=> {:id => 'form'} do |f| %>
Snippet of routes code:
get 'requests/new', to: 'requests#new', as: 'new_request'
post 'requests', to: 'requests#create'
Upvotes: 1
Views: 54
Reputation: 1954
In Rails 4, PATCH is used for updates. Could it be that your record is being created even when a checkpoint fails. This would cause Rails to think that the subsequent request is an update request, rather than create request.
Upvotes: 1