0

ユーザーが自分のページを編集するときに関数を呼び出す必要があります。

これが私のsettings_controller.rbです:

class SettingsController < ApplicationController
  def update
    @user = User.find(current_user.id)
    email_changed = @user.email != params[:user][:email]
    password_changed = !params[:user][:password].empty?
    successfully_updated = if email_changed or password_changed
      @user.update_with_password(params[:user])
    else
      @user.update_without_password(params[:user])
    end

    if successfully_updated
      # Sign in the user bypassing validation in case his password changed
      sign_in @user, :bypass => true
      //need to call action here
    else
      render "edit"
    end
  end
end

更新が成功した場合、ユーザーをリダイレクトする必要があります。

私のroutes.rbで:

devise_for :users, :controllers => {:registrations => 'registrations', :settings => 'settings'}

または私は何か間違ったことをしていますか?

4

1 に答える 1

2

settingsにルートはありませんdevise_for

工夫して見てください。RegistrationController

これを上書きできます:

class SettingsController < Devise::RegistrationsController
 def update
  @user = User.find(current_user.id)
  email_changed = @user.email != params[:user][:email]
  password_changed = !params[:user][:password].empty?
  successfully_updated = if email_changed or password_changed
    @user.update_with_password(params[:user])
  else
    @user.update_without_password(params[:user])
  end

  if successfully_updated
    # Sign in the user bypassing validation in case his password changed
    sign_in @user, :bypass => true
    //need to call action here
  else
    render "edit"
  end
 end
end

ルーティング:

devise_for :users, :controllers => {:registrations => 'settings'}
于 2012-07-19T13:17:26.843 に答える