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>