Ask A Question

Notifications

You’re not receiving notifications from this thread.

No route matches [GET] "/auth/facebook"

Henry Augustianno asked in Rails

Hi folks!

I am just starting to learn Rails, I want to make a simple OAuth Facebook login and display it after a successful login.
I always got No route matches [GET] "/auth/facebook" and can't find anything useful online.

here's a snippet of my codes:
routes.rb:

Rails.application.routes.draw do
  get '/hello', to: 'hello#world'
  root 'welcome#index'
  get '/auth/:provider/callback', to: 'sessions#create'
end
# app/controllers/sessions_controller.rb

class SessionsController < ApplicationController
  def create
    auth = request.env['omniauth.auth']
    session[:user_info] = {
      name: auth.info.name,
      email: auth.info.email,
      image: auth.info.image
    }
    redirect_to root_path
  end
end
<!-- app/views/welcome/index.html.erb -->

<h1>Hello, World!</h1>

<% if session[:user_info] %>
  <h2>Welcome <%= session[:user_info][:name] %>!</h2>
  <p>Email: <%= session[:user_info][:email] %></p>
  <img src="<%= session[:user_info][:image] %>" alt="Profile Image">
<% else %>
  <%= link_to "Sign in with Facebook", '/auth/facebook' %>
<% end %>
# config/initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, 'FACEBOOK_APP_ID', 'FACEBOOK_APP_SECRET'
end

thanks in advance!

Reply

I only use this gem so far

 gem 'omniauth-facebook'
gem 'omniauth' 
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,969+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.