I have a REST resource called Greetings.
Here is my routes file:
resources :greetings
I have a form to create or update a greeting as follows:
<%= form_tag(@greeting, :remote => true, :id => 'greeting_form') do %>
<%= text_area :greeting, :content, :rows => 3, :placeholder => "Type your message..." %>
<% end %>
note: I am using form_tag because this form also collects user data.
This is supposed to create a hidden field with method=> put but its not so it can't find the route.
Any ideas how I can get this to submit开发者_如何学Python to the update action?
Just write
<%= form_tag(@greeting, :remote => true, :id => 'greeting_form', :method => :put) do %>
and everything should be working.
You can use form_for
tag and still collect user data like this:
<%= form_for @greeting, :validate => true do |f| %>
<%= f.text_area :content, :rows => 3, :placeholder => "Type your message..." %>
<%= f.fields_for @user do |u| %>
<%= u.text_field :name %>
<% end %>
<% end
精彩评论