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 回答