i think there is a bug in how rails automatically detects if a
form_for should be a post or put when the controller is in a
namespace. can someone confirm this, or am i doing something wrong?
### specs
windows xp
ruby 1.8.6
rails 2.1.1
mysql 5
### in the terminal
rails bug_test
cd bug_test
# edit database.yml
ruby script/generate model User name:string
ruby script/generate controller admin/site_users
rake db:migrate
### config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.resources :users
map.namespace :admin do |admin|
admin.resources :site_users
admin.resources :roles
end
end
### controllers/admin/site_users_controller.rb
class Admin::SiteUsersController < ApplicationController
def index
@users = User.find(:all)
end
def new
@user = User.new
end
def edit
@user = User.find(params[:id])
end
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
flash[:notice] = ''User was successfully created.''
format.html { redirect_to( admin_site_users_path )}
format.xml { render :xml => @user, :status
=> :created, :location => @user }
else
flash.now[:error] = "We couldn''t set up that
account."
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status
=> :unprocessable_entity }
end
end
end
end
### views/admin/site_users/edit.html.erb
<h1> Editing a user erb</h1>
<%= error_messages_for :user %>
<h2>
<% if @user.respond_to?(:new_record?) && @user.new_record? %>
ERROR => NEW RECORD
<% else %>
OLD RECORD => form_for method should be put
<% end %>
</h2>
<% form_for(:user, :url => admin_site_user_path ) do |f| %>
<p><%= label_tag ''name'' %> <%= f.text_field
:name %></p>
<p><%= f.submit ''Update'' %></p>
<% end %>
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---