So I have this app that uses omniauth-facebook to autenticate users, a new user creates in the sessionscontroller:
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env['omniauth.auth'])
session[:user_id] = user.id
redirect_to root_url, notice: "Signed in!"
end
end
then it hits the user model:
class User < ActiveRecord::Base
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
user.name = auth["info"]["name"] unless auth["info"].blank?
user.email = auth["info"]["email"] unless auth["info"].blank?
user.save!
end
end
end
Then in my usercontroller I have something like this to display a user profil:
class UserController < ApplicationController
def show
@user = User.find(params[:id])
end
end
And in the show.html.erb I have something like this:
<%= @user.name %>, <%= @user.email %>
But I get the following error: Routing Error - uninitialized constant UsersController
My routes file:
Bummerang::Application.routes.draw do
resources :users, :only => :show
root to: 'static_pages#home'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
# autentications routes
match '/auth/:provider/callback', to: 'sessions#create'
match 'signout', to: 'sessions#destroy', as: 'signout'
match 'auth/failure', to: redirect('/')
end
It's a little difficult to tell what the problem here is: in the future, consider posting the entire error message and the code that the error message references as being bad.
Nevertheless, my guess is: your UsersController
is named UserController
. It should be pluralized. Change the name to UsersController
and this should work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.