class AddressesController < ApplicationController
def update
@address = Address.find(params[:id])
if @address.user != current_user
redirect_to :root
end
if @address.update_attributes params[:address]
flash[:notice] = "更新地址成功"
redirect_to :action => :edit, :id => @address
else
render :action => :edit, :id => @address
end
end
end
就这样一个简单的方法
页面显示了 更新地址成功 但是所有字段都没有更新
日志如下:
Started PUT "/addresses/1" for 127.0.0.1 at 2012-05-02 18:35:56 +0800
Processing by AddressesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"SHKjkV+LcF5xxe/ZZN/FE0CRUsC5jJNkPc0iplyacoU=", "address"=>{"province"=>"dd", "city"=>"dd", "area"=>"dd", "address"=>"dd",
"phone"=>"wewew"}, "commit"=>"更新", "id"=>"1"}
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 4 LIMIT 1
Address Load (0.2ms) SELECT `addresses`.* FROM `addresses` WHERE `addresses`.`id` = 1 LIMIT 1
CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 4 LIMIT 1
(0.1ms) BEGIN
(0.0ms) COMMIT
Redirected to http://0.0.0.0:3000/addresses/1/edit
Completed 302 Found in 4ms (ActiveRecord: 0.6ms)