所以我有这个应用程序,它使用omniauth-facebook 来验证用户,一个新用户在会话控制器中创建:
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
然后它到达用户模型:
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
然后在我的用户控制器中,我有这样的东西来显示用户配置文件:
class UserController < ApplicationController
def show
@user = User.find(params[:id])
end
end
在 show.html.erb 我有这样的东西:
<%= @user.name %>, <%= @user.email %>
但我收到以下错误:Routing Error - uninitialized constant UsersController
我的路线文件:
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