路由错误 - 未初始化的常量UsersController? omn​​iauth Facebook的

时间:2012-07-04 14:51:28

标签: ruby-on-rails ruby ruby-on-rails-3

所以我有这个应用程序使用omniauth-facebook来验证用户,新用户在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

然后它命中用户模型:

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

然后在我的usercontroller中我有这样的东西来显示用户profil:

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

1 个答案:

答案 0 :(得分:23)

告诉问题是什么有点困难:将来,请考虑发布整个错误消息以及错误消息引用的代码是错误的。

然而,我的猜测是:您的UsersController被命名为UserController。它应该是多元化的。将名称更改为UsersController,这应该有效。