1

introducir la descripción de la imagen aquí


Routes.rb

Rails.application.routes.draw do
  root 'pages#home'

  devise_for :users,
             path: '',
             path_names: {sign_in: 'login', sign_out: 'logout', edit:    'profile', sign_up: 'registration'},
             contollers: {:omniauth_callbacks => 'users/omniauth_callbacks'}

end


Controlador: omniauth_callbacks_controller.rb

class Users::OmniauthCallbacksController <   Devise::OmniauthCallbacksController

def facebook # You need to implement the method below in your model (e.g. app/models/user.rb) @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

end


Modelo : User

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :confirmable, :omniauthable, :omniauth_providers => [:facebook]

  validates :fullname, presence: true, length: {maximum: 50}

  def self.from_omniauth(auth)
    user = User.where(email: auth.info.email).first

    if user
      return user
    else
      where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
        user.email = auth.info.email
        user.password = Devise.friendly_token[0,20]
        user.fullname = auth.info.name   # assuming the user model has a name
        user.image = auth.info.image # assuming the user model has an image
        user.uid = auth.uid
        user.provider = auth.provider

        # If you are using confirmable and the provider(s) you use validate emails,
        # uncomment the line below to skip the confirmation emails.
        user.skip_confirmation!
      end
    end
  end
end

1 respuesta 1

1

Es un typo en tu archivo de rutas, pusiste contollers en vez de controllers, entonces debería ser:

devise_for :users,
             path: '',
             path_names: {sign_in: 'login', sign_out: 'logout', edit:    'profile', sign_up: 'registration'},
             controllers: {:omniauth_callbacks => 'users/omniauth_callbacks'}
1
  • Esa era el error, ya quedo funcional con su orientación y configurando u parametrp que faltaba en facebook, routes s modifio y quedo funcionando dejandolo así: controllers: {:omniauth_callbacks => 'omniauth_callbacks'} Commented el 15 nov. 2017 a las 18:16

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.