form_for -> put/post problem

I am having trouble getting form_for to use method :put for my edit
view which has been driving me crazy. in the controller i have
User.find, not User.new so i can't figure out why this always
generates a method post.

i have tried the following and they all generate method = post, even
when i specify :method => :put!!!

<% form_for(:user) do |f| %>
<% form_for(:user, @user) do |f| %>
<% form_for(:user, @user, :url => admin_site_user_path ) do |f| %>
<% form_for :user, @usert, :url => admin_site_user_path, :html =>
{ :method => :put, :class => "edit_post", :id => "edit_post_14" } do |
f> %>
<% form_for(:user, :url => admin_site_user_path, :method => :put ) do

f> %>

digging through rails i found form_helper.rb with
apply_form_for_options! which looks like where rails decides if it
should be a put or post and to where.

      def apply_form_for_options!(object_or_array, options) #:nodoc:
      ......
        html_options =
          if object.respond_to?(:new_record?) && object.new_record?
            { :class => dom_class(object, :new), :id =>
dom_id(object), :method => :post }
          else
            { :class => dom_class(object, :edit), :id =>
dom_id(object, :edit), :method => :put }
          end
        ....
. end

there is the "if object.respond_to?(:new_record?) &&
object.new_record?" so i added that to my view and that detects things
correctly, but the form still is a post???

see my code below and HOPEFULLY tell me what i am doing wrong

i have a User model created by restful_authentication

## controller
class Admin::SiteUsersController < ApplicationController
  before_filter :login_required
  require_role :admin
  def edit
    @user = User.find(params[:id])
    render :layout => false
  end
end

## edit view
<%= error_messages_for :user %>
<h2>
<% if @user.respond_to?(:new_record?) && @user.new_record? %>
  NEW RECORD should be post
<% else %>
  OLD RECORD should be put
<% end %>
</h2>
<% form_for(:user, :url => admin_site_user_path ) do |f| %>
  <%= f.text_field :login %>
  <%= f.text_field :email %>
  <%= f.submit 'Update' %>
<% end %>

## generated html
<h2>OLD RECORD should be put</h2>
<form action="/admin/site_users/14" method="post">
  <div style="margin:0;padding:0">
    <input name="authenticity_token" type="hidden"
value="41ae3eb40f87bff79db0ab1aa52a13a5fef7a0e8" />
  </div>
  <input id="user_login" name="user[login]" size="30" type="text"
value="scott" />
  <input id="user_email" name="user[email]" size="30" type="text"
value="scott@example.com" />
  <input id="user_submit" name="commit" type="submit" value="Update" /

</form>

i am still having trouble with this. anyone have any insight how to
fix this?

Try this:

<% form_for :user, :url => user_path(current_user), :html => {:method
=> :put} do |f| -%>

Note that the put method is not officially supported, so when the HTML
is directed as above, a hidden variable _method is introduced which
the Rails router than interprets as a PUT eventhough technically the
form is being submitted as a POST.

HTH,

Han Yuan

Scott Nj wrote:

<% form_for(:user) do |f| %>
<% form_for(:user, @user) do |f| %>
<% form_for(:user, @user, :url => admin_site_user_path ) do |f| %>
<% form_for :user, @usert, :url => admin_site_user_path, :html =>
{ :method => :put, :class => "edit_post", :id => "edit_post_14" } do |
f> %>
<% form_for(:user, :url => admin_site_user_path, :method => :put ) do
>f> %>

Wow, Scott. Sorry to hear you're having so much trouble. I was just
working with a form_for today, but my problem was getting the multipart
working correctly. But to address your issue, I simply do this:

form_for(@user) do |f|

and it works. The only difference between what I do and your list of
trials is that I actually specify the instance variable instead of the
symbol. I would like to think that would not matter, but you never know.

And in case you need multipart for file uploads:

form_for( @user, :html => {:multipart => true}) do |f|

Peace.

hyuan wrote:

Try this:

<% form_for :user, :url => user_path(current_user), :html => {:method
=> :put} do |f| -%>

Note that the put method is not officially supported, so when the HTML
is directed as above, a hidden variable _method is introduced which
the Rails router than interprets as a PUT eventhough technically the
form is being submitted as a POST.

HTH,

Han Yuan

Thanks hyuan , this does works.

I was routes
  map.resources "parties" , :controller => "political_parties"
so there is no way i can use
form_for(@political_party) do |f|

as it will create wrong pathname.
so i did this

<% form_for :political_party, :url => party_path(@political_party) ,
:html => {:method => :put } do |f| %>