ユーザーが自分のアカウントを編集できるようにしようとしています (簡単ですよね?)
これが私の更新方法です:
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
なぜこれが機能しないのかわかりません... 他の誰かがこの問題に遭遇しましたか?