Rails form_for routing issues
I have a form that I am using to try and update a field in "things". However, I am having serious problems that probably go down to something silly.
My code looks like this:
<% form_for :thing, :url => { :action => "update" } do |f| %>
<%= f.collection_select :status_id, Thing.statuses, :first, :last %>
<%= f.submit 'Submit' %>
<% end %>
This looks correct to me (@thing exists BTW), however, when I submit, I get
Unknown action
No action responded to 145
etc. etc. The URL is http: // localhost: 3000 / things / 145 . What am I doing wrong?
+1
a source to share
3 answers
If you've used RESTful routing (and I assume you did), you can simply do this:
<% form_for @thing do |f| %>
<%= f.collection_select :status_id, Thing.statuses, :first, :last %>
<%= f.submit 'Submit' %>
<% end %>
And this will indicate the correct action depending on whether it @thing
is new_record?
or not.
+4
a source to share