Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.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 轨道&x2B;设计:如果用户登录?不起作用_Ruby On Rails_Devise_Omniauth - Fatal编程技术网

Ruby on rails 轨道&x2B;设计:如果用户登录?不起作用

Ruby on rails 轨道&x2B;设计:如果用户登录?不起作用,ruby-on-rails,devise,omniauth,Ruby On Rails,Devise,Omniauth,我首先发现了一个问题,该问题没有显示为用户使用以下逻辑登录: \u header.html.erb: <% if user_signed_in? %> <li><%= link_to "Log out", destroy_user_session_path, method: :delete %></li> <% else %> <li><%= link_to "S

我首先发现了一个问题,该问题没有显示为用户使用以下逻辑登录:

\u header.html.erb

<% if user_signed_in? %>
          <li><%= link_to "Log out", destroy_user_session_path, method: :delete %></li>
        <% else %>
          <li><%= link_to "Sign in", new_user_session_path %></li>
        <% end %>
Rails.application.routes.draw do

  mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
  devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }

  root 'productlines#index'

end
class OmniauthCallbacksController < Devise::OmniauthCallbacksController 
  def google_oauth2
    @user = User.from_omniauth(request.env["omniauth.auth"])
    if @user.persisted?
      flash.notice = "Signed in through Google"
      sign_in_and_redirect @user
      return
    else
      session["devise.user_attributes"] = @user.attributes
      flash.notice = "You are almost Done! Please provide a password to finish setting up your account"
      redirect_to new_user_registration_path
    end
  end
end
而且我一直被循环回登录页面(即使有有效的凭证)

虽然我可以在RailsAdmin控制台上看到登录计数和上次登录日期显示为他们正在登录,但我的用户会话似乎无法正常工作

这是我的用户.rb

before_filter :authenticate_user!
class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :omniauthable, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable

  belongs_to :company

  has_and_belongs_to_many :productlines
end
omniauth\u回调\u controller.rb

<% if user_signed_in? %>
          <li><%= link_to "Log out", destroy_user_session_path, method: :delete %></li>
        <% else %>
          <li><%= link_to "Sign in", new_user_session_path %></li>
        <% end %>
Rails.application.routes.draw do

  mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
  devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }

  root 'productlines#index'

end
class OmniauthCallbacksController < Devise::OmniauthCallbacksController 
  def google_oauth2
    @user = User.from_omniauth(request.env["omniauth.auth"])
    if @user.persisted?
      flash.notice = "Signed in through Google"
      sign_in_and_redirect @user
      return
    else
      session["devise.user_attributes"] = @user.attributes
      flash.notice = "You are almost Done! Please provide a password to finish setting up your account"
      redirect_to new_user_registration_path
    end
  end
end

是否要首先对您的用户设置异常?这样,它就不会在设置当前_user/@user/etc之前尝试运行身份验证。例如,如果根是索引:

在\u操作之前:验证\u用户!,:除了=>[:索引]

然后-确保有
better\u错误
gem,并在
语句中加入一些胡说八道的jibberish,如果用户登录?
语句,刷新页面以触发浏览器中的控制台。查看是否首先设置了
@user
当前用户
或您正在使用的内容。然后我将从那里向后调试

最后,这里是一个stackoverflow链接,我遇到了一个类似的问题,下面是一些答案:


是否要首先对您的用户设置异常?这样,它就不会在设置当前_user/@user/etc之前尝试运行身份验证。例如,如果根是索引:

在\u操作之前:验证\u用户!,:除了=>[:索引]

然后-确保有
better\u错误
gem,并在
语句中加入一些胡说八道的jibberish,如果用户登录?
语句,刷新页面以触发浏览器中的控制台。查看是否首先设置了
@user
当前用户
或您正在使用的内容。然后我将从那里向后调试

最后,这里是一个stackoverflow链接,我遇到了一个类似的问题,下面是一些答案:


当您尝试对inDoes进行签名时,请显示rails日志输出。开始“/”表示您已重定向到登录页面?@asiniy我相信这表示它已重定向到根路径。您是否使用OmniAuth登录?如果是,您是否在您的用户模型中实现了
self.from\u OmniAuth
方法?我以前使用过OmniAuth,但在调试时对其进行了注释。请在尝试签名时显示rails日志输出。开始“/”表示您重定向到了登录页面?@asiniy我相信这表示它重定向到了根路径。您使用OmniAuth登录了吗?如果是,您是否在您的用户模型中实现了
self.from_omniauth
方法?我以前使用过OmniAuth,但为了调试它,我对它进行了注释。问题不在于\u操作之前的
:验证\u用户-这是因为即使有正确的凭据,用户也无法真正登录。问题不在于\u操作之前的
:验证\u用户-这意味着用户永远无法真正登录,即使拥有正确的凭据。