开发者

Rails is not creating hidden field for put method on an update form

开发者 https://www.devze.com 2023-03-26 16:53 出处:网络
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:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消