Vì vậy, tôi đã ứng dụng này sử dụng omniauth-facebook để autenticate người dùng, người dùng mới tạo ra trong sessionscontroller:Lỗi định tuyến - UsersController không xác định không được khởi tạo? 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
sau đó nó chạm vào mô hình người dùng:
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
Sau đó, trong bộ điều khiển người dùng của tôi Tôi có thông tin như thế này để hiển thị tiểu sử của người dùng:
class UserController < ApplicationController
def show
@user = User.find(params[:id])
end
end
Và trong show.html.erb tôi có nội dung như sau:
<%= @user.name %>, <%= @user.email %>
Nhưng tôi nhận được lỗi sau: Routing Error - uninitialized constant UsersController
tuyến My 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
Đó là vấn đề, thực ra tôi là lỗi lỗ là: Lỗi định tuyến - hằng số không xác định UsersController - thử chạy các tuyến đường rake. – SHUMAcupcake
cảm ơn! vừa giải quyết cùng một vấn đề cho tôi! – dopplesoldner
Lưu ý rằng 'user' trong tên tập tin cũng cần phải được số nhiều:' users_controller.rb'. – Dennis