Hi,
I'm trying to create a custom for user editing and I see two problems.
1) Using edit_user_registration_path generates the following url "/users/edit" with method="post"
2) After setting the url by myself, using url: "/users", I can't set the http method to put. Neither using method: :put or html: {method: :put}.
The @user object is filled with data and is already persisted. I'm usgin simple_for version 1.5.2 on rails 3.2.3.
I believe this is a bug.
This is how Rails works. If the @user is persisted so the Rails will use the edit path and the method post.
You need to do:
simple_form_for @user, :url => "/users", :method => :put
If this doesn't work it is a Rails issue. SimpleForm only delegates to form_for
Hi Rafael, Thanks for answering that fast. :)
However I'm not sure I understood what you said. Did you understand the issue, more specifically the second part?
If I do that:
<%= simple_form_for User.first, url: {action: :update, controller: 'users/registrations'}, :method => :put, validate: true do |f| %>
Thats what I get:
<form accept-charset="UTF-8" action="/users" class="simple_form user" data-validate="true" id="edit_user_1" method="post" novalidate="novalidate">
Also, you say rails will use http method POST for persisted records?
This is not what is stated here: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for-label-Resource-oriented+style
So, are you sure you understood the problem? Am I missing something here?
Oops, If the record is persisted rails uses PUT and update.
Also I saw the code and if you pass the :method key rails will use.
Please report back if it works, or if we need to open an issue on Rails.
In the code I sent before, the key/value :method => : put is already there. So maybe it is an Rails issue? I'm using 3.2.3.
@felipero May I ask you what's the validate option you're giving to SimpleForm (that apparently generates data-validate)?
form_for should just work, as in this example from Rails docs:
# For example, if <tt>@post</tt> is an existing record you want to edit
<%= form_for @post do |f| %>
...
<% end %>
# is equivalent to something like:
<%= form_for @post, :as => :post, :url => post_path(@post), :method => :put, :html => { :class => "edit_post", :id => "edit_post_45" } do |f| %>
...
<% end %>
You can give it a try using only form_for to see if that works. The same arguments should work for both.
Forget it. Looks like rails will use a input hidden to pass the put method. That happens because browsers doesn't support PUT and DELETE. Not sure why it is not finding my action anyway.
Thanks for your time.
Ok, thanks for reporting back, and let us know if you have any other issues.
Most helpful comment
Forget it. Looks like rails will use a input hidden to pass the put method. That happens because browsers doesn't support PUT and DELETE. Not sure why it is not finding my action anyway.
Thanks for your time.