Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在Desive gem的更新控制器(编辑用户)中添加调用操作?_Ruby On Rails_Devise - Fatal编程技术网

Ruby on rails 如何在Desive gem的更新控制器(编辑用户)中添加调用操作?

Ruby on rails 如何在Desive gem的更新控制器(编辑用户)中添加调用操作?,ruby-on-rails,devise,Ruby On Rails,Devise,当用户编辑页面时,我需要调用函数 以下是我的设置\u 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

当用户编辑页面时,我需要调用函数

以下是我的设置\u 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

或者我做错了什么?

design\u中没有
设置
路由

您可以覆盖以下内容:

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

我建议您为这类东西研究designe()。重新发明轮子毫无意义。比灵顿,我需要改变控制器的设置。我会编辑问题,你能看看我的代码吗?控制器不是超控的。我没有对Desive做任何事情,所以我不会有太多帮助。如果是我,我会发布一个新问题,确保你使用Desive标签。有很多人在stackoverflow上问Desive问题,所以我知道这是一个很受欢迎的宝石。你的代码需要重构。我从Desive/wiki上得到的,它不是我的代码。)
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'}