I've been stuck at work for this weird error message.
I have a form, which structured like:
<%=form_for @cnf, :url=>{:action=>"tpg_note"} do |c|%>
<%= c.hidden_field 'cust_id'%>
<div>
<p><h4>Date</h4></p>
<%=c.text_field :testing_tpg_results_date %>
</div>
<p><h4>Results valid?</h4></p>
<span class='moduleradio'><%=c.radio_button(:testing_tpg_success, 'Y', :checked=>true)%>
</span>
<span class="text">
Yes
</span>
<span class='moduleradio'> <%=c.radio_button(:testing_tpg_success, 'N',:checked=>true)%>
</span>
<span class="text">
No
</span>
<p><h4>Notes</h4></p>
<div id='comment'>
<%= c.cktext_area :tpg_note %>
</div>
<%= submit_tag "Save" %>
<% end %>
form_for points to an url action "tpg_note". Once save button clicked, it's executing tpg_note as coded. But an error message shows up on the screen as:
The update action is not defined in CustFlows controller
Why the hell it looks for "update"? form_for specify the action as tpg_note and after save button clicked, the address bar does show http://localhost/cust_flows/tpg_note
Why update then?
Through exam the Network transaction, I found that the page was trying to be accessed as "POST", but it's not found.
Then a couple of commands were run locally to determine what's the real transaction is going on.
localhost:~ future$ curl --data "_method=put" http://localhost/cust_flows/tpg_note
localhost:~ future$ curl --data "_method=post" http://localhost/cust_flows/tpg_note
When the method is "POST", it actually runs fine. So, that means the culprit comes in when it's "PUT". All of a sudden, it all pieces together. In rails, form_for by default is PUT method. Because of PUT, it was looking for associated "update" method. Since I redirect to a different function, it got lost. The fix is easy, just force form_for to use POST. And problems went away!