简体   繁体   English

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

[英]Routing Error - uninitialized constant UsersController? omniauth-facebook

So I have this app that uses omniauth-facebook to autenticate users, a new user creates in the sessionscontroller: 所以我有这个应用程序使用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

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: 然后在我的usercontroller中我有这样的东西来显示用户profil:

class UserController < ApplicationController
  def show
    @user = User.find(params[:id])
  end
end

And in the show.html.erb I have something like this: 在show.html.erb我有这样的事情:

<%= @user.name %>, <%= @user.email %>

But I get the following error: Routing Error - uninitialized constant UsersController 但是我收到以下错误: 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 . 不过,我的猜测是:你的UsersController被命名为UserController It should be pluralized. 它应该是多元化的。 Change the name to UsersController and this should work. 将名称更改为UsersController ,这应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Unicorn和omniauth-facebook - 未初始化的恒定OmniAuth - Unicorn and omniauth-facebook - uninitialized constant OmniAuth Devise Omniauth-Facebook“未初始化的常量OmniAuth” - Devise Omniauth-Facebook “uninitialized constant OmniAuth” 路由错误未初始化的常量UsersController - Routing Error uninitialized constant UsersController Ruby on Rails-路由错误(未初始化的常量UsersController) - Ruby on Rails - Routing Error (uninitialized constant UsersController) Rails路由错误:未初始化的常量UsersController - Rails Routing Error: uninitialized constant UsersController 对于Facebook,使用Devise和Omniauth:路由错误未初始化的常量OmniauthCallbacksController - Using Devise and Omniauth, for facebook : Routing Error uninitialized constant OmniauthCallbacksController 未初始化的常量用户omniauth_callbacks_controller与gem omniauth-facebook在ruby on rails app - uninitialized constant Users for omniauth_callbacks_controller with gem omniauth-facebook in ruby on rails app Omniauth-facebook redirect_uri错误 - Omniauth-facebook redirect_uri error Rails 3.1-设计-CanCan:“ ../ users / sign_out”收到路由错误“未初始化的常量UsersController” - Rails 3.1 - Devise - CanCan: “../users/sign_out” gets routing error “uninitialized constant UsersController” 未初始化的常量UsersController :: Children - Uninitialized constant UsersController::Children
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM