Omniauth Facebook:注册后重定向无效

时间:2019-12-11 12:49:22

标签: ruby-on-rails

我有一个注册页面,该页面基本上是一个两步的表单,是用邪恶的宝石创建的。摆好姿势后,新用户将被重定向到个人资料页面,该页面需要创建才能使用该网站。以下是我与这些步骤有关的控制程序: 用户

class UsersController < ApplicationController

  def index
    @users = User.all
  end

  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])
    if @user.save
      session[:user_id] = @user.id
      redirect_to user_steps_path
    else
      render :new
    end
  end

  private

  def user_params
    params.require(:user).permit(:email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :street, :house_number, :city, :zip_code)
  end

end

注册:

class Users::RegistrationsController < Devise::RegistrationsController

def new
  super
end

def create
  super
end

def update
  super
end

protected
    def after_sign_up_path_for(resource)
        user_steps_path 
    end

    def after_update_path_for(resource)
        user_steps_path
    end
end

用户步骤:

class UserStepsController < ApplicationController
    include Wicked::Wizard
    steps :address


    def show
      @user = current_user
      render_wizard
    end


    def update
      @user = current_user
      @user.update!(user_params)
      render_wizard @user
    end

    private

    def user_params
        params.require(:user).permit(:email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :street, :house_number, :city, :zip_code)
    end

    def redirect_to_finish_wizard(options = nil, params = nil)
        redirect_to new_user_profile_path(current_user)
    end

end

现在终于是我的Omniauth回调控制器:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
      @user = User.from_omniauth(request.env["omniauth.auth"])

    if @user.persisted?
      sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
      set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format?
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def failure
    redirect_to root_path
  end

不幸的是,重定向无效。基本上,我尝试将其更改为实际需要的路径,并且该路径也适用于“正常”注册:

redirect_to new_user_profile_path(current_user)

但这会导致我进入以下本地主机页面:

http://localhost:3000/#_=_

实际上,在Facebook叹了口气之后,我尝试的任何路径都会将我引向此。我为开发人员嘲笑了Facebook,据我了解,如果有实际的托管服务,则可以更改重定向路径。在使用localhost的同时也可以进行开发阶段吗?太好了!谢谢。

1 个答案:

答案 0 :(得分:0)

在找到答案时,我走了一步,这导致了以下问题。 Facebook omniauth redirect_to user_steps_path

我可以通过更改OmniAuthController中的语句来解决。答案可以在上面的链接下找到。