Hello,
I have a form that should be a POST method, but Rails insist to put a
hidden field "_method" that has the value "put" does anyone
knows why?
Thanks,
David Sousa
Controller: -------------------------------
def new
@user = @current_user
end
-------------------------------------------
View: -------------------------------------
<% semantic_form_for @user, :url => profile_reset_password_url do |form|
-%>
<% form.inputs -%>
<%= form.input :password -%>
<%= form.input :new_password -%>
<%= form.input :new_password_confirmation -%>
<% end -%>
<%= form.buttons %>
<% end -%>
-------------------------------------------
Routes: -----------------------------------
map.namespace :profile do |profile|
profile.resource :reset_password, :only => [:new, :create]
end
-------------------------------------------
Output: -----------------------------------
<form method="post" id="edit_user_2"
class="formtastic user"
action="http://localhost:3000/profile/reset_password"><div
style="margin: 0pt; padding: 0pt; display: inline;">
<input type="hidden" value="put"
name="_method">
<input type="hidden"
value="YttRSHr2SzCqC4FbQccH6QgcWVKRkf1IBIIXnQhuaFw="
name="authenticity_token"></div>
<fieldset
class="inputs"><legend><span>Informações</span></legend><ol>
<li id="user_password_input" class="password
required"><label
for="user_password">Password<abbr
title="required">*</abbr></label><input
type="password" size="50"
name="user[password]" id="user_password"></li>
<li
id="user_new_password_input" class="password
required"><label
for="user_new_password">New password<abbr
title="required">*</abbr></label><input
type="password" size="50"
name="user[new_password]"
id="user_new_password"></li> <li
id="user_new_password_confirmation_input" class="password
required"><label
for="user_new_password_confirmation">New password
confirmation<abbr
title="required">*</abbr></label><input
type="password" size="50"
name="user[new_password_confirmation]"
id="user_new_password_confirmation"></li>
</ol></fieldset> <fieldset
class="buttons"><ol><li
class="commit"><input type="submit" value="Save
User" name="commit"
id="user_submit"></li></ol></fieldset>
</form>
-------------------------------------------
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On 17 Aug 2010, at 05:19, David Sousa wrote:> I have a form that should be a POST method, but Rails insist to put a > hidden field "_method" that has the value "put" does anyone knows why?Since @user already exists in the database (you assign an existing record @current_user to it) and is not a new_record?, Rails assumes you want to update the record aka a PUT request. Probably just adding :method => :post as a parameter will do the trick.> Controller: ------------------------------- > def new > @user = @current_user > end > ------------------------------------------- > > View: ------------------------------------- > <% semantic_form_for @user, :url => profile_reset_password_url do | > form| > -%> > <% form.inputs -%> > <%= form.input :password -%> > <%= form.input :new_password -%> > <%= form.input :new_password_confirmation -%> > <% end -%> > <%= form.buttons %> > > <% end -%> > ------------------------------------------- > > Routes: ----------------------------------- > map.namespace :profile do |profile| > profile.resource :reset_password, :only => [:new, :create] > end > ------------------------------------------- > > Output: ----------------------------------- > <form method="post" id="edit_user_2" class="formtastic user" > action="http://localhost:3000/profile/reset_password"><div > style="margin: 0pt; padding: 0pt; display: inline;"> > > <input type="hidden" value="put" name="_method"> > <input type="hidden" > value="YttRSHr2SzCqC4FbQccH6QgcWVKRkf1IBIIXnQhuaFw=" > name="authenticity_token"></div> > > <fieldset class="inputs"><legend><span>Informações</span></legend><ol> > <li id="user_password_input" class="password required"><label > for="user_password">Password<abbr > title="required">*</abbr></label><input type="password" size="50" > name="user[password]" id="user_password"></li> <li > id="user_new_password_input" class="password required"><label > for="user_new_password">New password<abbr > title="required">*</abbr></label><input type="password" size="50" > name="user[new_password]" id="user_new_password"></li> <li > id="user_new_password_confirmation_input" class="password > required"><label for="user_new_password_confirmation">New password > confirmation<abbr title="required">*</abbr></label><input > type="password" size="50" name="user[new_password_confirmation]" > id="user_new_password_confirmation"></li> </ol></fieldset> <fieldset > class="buttons"><ol><li class="commit"><input type="submit" > value="Save > User" name="commit" id="user_submit"></li></ol></fieldset> > > </form> > --------------------------------------------- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Peter, just adding :method => :post worked. Let me ask one more thing, just after a submit the form, the firefox open a dialog box asking me each of users that is in a list that I want to change the password. Actually does not matter each you pick, the user that you are logon on the site gets the pass changed. Tks again. David Sousa -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.