我试图允许用户编辑他们的帐户(很简单,嗯?)
这是我的更新方法:
def update
@user = current_user
# @user.attributes = {'mail_chimp_newsletters' => []}.merge(params[:user])
if @user.update_attributes(params[:user])
sign_in @user, :bypass => true
redirect_to edit_account_path, :notice => 'Account has been updated!'
else
redirect_to edit_account_path, :flash => { :alert => "Account could not be updated. Please try again" }
end
end
路线:
match 'account/edit' => 'settings#edit', :as => 'edit_account', :via => :get
match 'accounts' => 'settings#update', :as => 'accounts', :via => :put
HTML 表单:
<%= form_for @user, :url => accounts_url, :method => :put, :html => { :id => "personal-info-form", :class => "hide" } do |f| %>
提交表单后,这将转储到console
:
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 43008 LIMIT 1
(0.2ms) BEGIN
User Exists (36.1ms) SELECT 1 FROM `users` WHERE (`users`.`username` = BINARY 'test@test.com' AND `users`.`id` != 43008) LIMIT 1
User Exists (33.4ms) SELECT 1 FROM `users` WHERE (`users`.`email` = BINARY 'test@test.com' AND `users`.`id` != 43008) LIMIT 1
(0.1ms) ROLLBACK
我不确定为什么这不起作用......还有其他人遇到这个问题吗?