Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.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 设计+;Heroku上的omniauth路由问题_Ruby On Rails_Facebook_Heroku_Devise_Omniauth - Fatal编程技术网

Ruby on rails 设计+;Heroku上的omniauth路由问题

Ruby on rails 设计+;Heroku上的omniauth路由问题,ruby-on-rails,facebook,heroku,devise,omniauth,Ruby On Rails,Facebook,Heroku,Devise,Omniauth,我在这件事上花了好几个小时。。。我有一个Desive和omniauth设置,允许用户使用他们的Facebook帐户登录。我正在使用以下gem版本: Installing devise (1.4.7) Installing oauth2 (0.4.1) Installing oa-oauth (0.2.6) Installing omniauth (0.2.6) 在我的Desive初始值设定项中包含应用程序id和密码: config.omniauth :facebook, 'app_id', '

我在这件事上花了好几个小时。。。我有一个Desive和omniauth设置,允许用户使用他们的Facebook帐户登录。我正在使用以下gem版本:

Installing devise (1.4.7)
Installing oauth2 (0.4.1)
Installing oa-oauth (0.2.6)
Installing omniauth (0.2.6)
在我的Desive初始值设定项中包含应用程序id和密码:

config.omniauth :facebook, 'app_id', 'app_secret',
          {:scope => 'email, offline_access', :client_options => {:ssl => {:verify => false}}}
虽然我也尝试过,但运气不好:

config.omniauth :facebook, 'app_id', 'app_secret',
          # {:scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
get '/users/auth/:provider' => 'user/authentications#passthru'
我的用户模型中有:omniauthable指令,我在routes文件中定义了自己的回调控制器:

devise_for :users, :controllers => { :omniauth_callbacks => 'user/authentications', :registrations => 'registrations' }

root :to => 'pages#home'
我还尝试将此添加到routes文件,但没有成功:

config.omniauth :facebook, 'app_id', 'app_secret',
          # {:scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
get '/users/auth/:provider' => 'user/authentications#passthru'
这是我的身份验证控制器:

class AuthenticationsController < Devise::OmniauthCallbacksController
  def index
    @authentications = current_user.authentications if current_user
  end

  def facebook
    omniauth = request.env["omniauth.auth"]
    authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
    if authentication
      flash[:notice] = "Signed in successfully."
      sign_in_and_redirect(:user, authentication.user)
    elsif current_user
      current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
      flash[:notice] = "Authentication successful."
      redirect_to authentications_url
    else
      user = User.new
      user.apply_omniauth(omniauth)
      if user.save
        flash[:notice] = "Signed in successfully."
        sign_in_and_redirect(:user, user)
      else
        session[:omniauth] = omniauth.except('extra')
        redirect_to new_user_registration_url
      end
    end
  end

  def passthru
    render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
  end

  def destroy
    @authentication = current_user.authentications.find(params[:id])
    @authentication.destroy
    flash[:notice] = "Successfully destroyed authentication."
    redirect_to authentications_url
  end
end
我试图重置我的数据库,但也没用

以下是我从Heroku出发的路线:

        new_user_session GET    /users/sign_in(.:format)               {:action=
>"new", :controller=>"devise/sessions"}
            user_session POST   /users/sign_in(.:format)               {:action=
>"create", :controller=>"devise/sessions"}
    destroy_user_session GET    /users/sign_out(.:format)              {:action=
>"destroy", :controller=>"devise/sessions"}
  user_omniauth_callback        /users/auth/:action/callback(.:format) {:action=
>/facebook/, :controller=>"user/authentications"}
           user_password POST   /users/password(.:format)              {:action=
>"create", :controller=>"devise/passwords"}
       new_user_password GET    /users/password/new(.:format)          {:action=
>"new", :controller=>"devise/passwords"}
      edit_user_password GET    /users/password/edit(.:format)         {:action=
>"edit", :controller=>"devise/passwords"}
                         PUT    /users/password(.:format)              {:action=
>"update", :controller=>"devise/passwords"}
cancel_user_registration GET    /users/cancel(.:format)                {:action=
>"cancel", :controller=>"registrations"}
       user_registration POST   /users(.:format)                       {:action=
>"create", :controller=>"registrations"}
   new_user_registration GET    /users/sign_up(.:format)               {:action=
>"new", :controller=>"registrations"}
  edit_user_registration GET    /users/edit(.:format)                  {:action=
>"edit", :controller=>"registrations"}
                         PUT    /users(.:format)                       {:action=
>"update", :controller=>"registrations"}
                         DELETE /users(.:format)                       {:action=
>"destroy", :controller=>"registrations"}
                    root        /                                      {:control
ler=>"pages", :action=>"home"}

非常感谢您的帮助。如果您需要任何其他信息,请告诉我。我知道它很小,但我觉得我已经尝试了上千种不同的方法,但都没有效果。

我认为,您的authenicatine行应该使用find_或create

authentication = Authentication.find_or_create_by_provider_and_uid(omniauth['provider'], omniauth['uid']) 身份验证=身份验证。通过提供程序和uid查找或创建(omniauth['provider'],omniauth['uid']) 最后我换了衣服

devise_for :users, :controllers => { :omniauth_callbacks => 'user/authentications', :registrations => 'registrations' }


它开始在本地和Heroku上工作。

您的“passthru”操作不是在呈现404.html吗。如果您正在执行get'/users/auth/:provider'=>“user/authentications#passthru”,则它是,但我当前未使用它。我在查找后检查身份验证是否为零。如果它是nil,则在我的控制器中该方法的下一步创建它。