自定义装置控制器正在重定向到错误的路径

时间:2019-06-13 19:45:54

标签: ruby-on-rails ruby devise

我的注册路线是users / sign_up / speed1等。但是,如果出现设计错误(例如密码不匹配),则会将用户重定向到“ / users”路径。功能上,它应重定向回同一页面,并让用户重新输入新密码。有任何更新吗?

new_package

这是我的路线文件

class RegistrationsController < Devise::RegistrationsController
  def new
    super
  end

  def create
    super
  end

  def update
    super
  end

  def speed1
    build_resource
    yield resource if block_given?
    respond_with resource
  end

  def speed2
    build_resource
    yield resource if block_given?
    respond_with resource
  end

  def speed3
    build_resource
    yield resource if block_given?
    respond_with resource
  end

  def speed4
    build_resource
    yield resource if block_given?
    respond_with resource
  end

  def speed5
    build_resource
    yield resource if block_given?
    respond_with resource
  end

  protected

  def after_sign_up_path_for(resource)
    if current_user.role == 'speed1' || current_user.role == 'speed2' || current_user.role == 'speed3' || current_user.role == 'speed4' || current_user.role == 'speed5'
      '/subscription/new' # Or :prefix_to_your_route
    else
      '/'
    end
  end
end

1 个答案:

答案 0 :(得分:0)

您可以将其添加到application_controller.rb中,它将返回到用户访问的最后一页,即root_path

private

# If your model is called User
def after_sign_in_path_for(resource)
  session["user_return_to"] || root_path
end