我使用设计连接twitter和facebook,我有两个问题: 当我运行我的应用程序时:
http://localhost:3000/users/10/finish_signup
我有第一个问题:
LoadError in UserController#finish_signup
Expected ../app/controllers/user_controller.rb to define UserController
当我重新加载此链接时,我遇到了第二个问题:
Routing Error
uninitialized constant UserController
在这里,我的路线:
Thuchanh::Application.routes.draw do
devise_for :users, :controllers => { omniauth_callbacks: 'omniauth_callbacks' }
match '/users/:id/finish_signup', :to => 'user#finish_signup', via: [:get, :patch], :as => :finish_signup
get "user/new"
get "user/finish_signup"
root :to => "welcome#index"
get '/users/:id', :to => 'welcome#sucess', :as => "user"
resources :users
我的user_controller
class UsersController < ApplicationController
def show
end
def edit
end
def update
respond_to do |format|
if @user.update(user_params)
sign_in(@user == current_user ? @user : current_user, :bypass => true)
format.html { redirect_to @user, notice: 'Your profile was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
def finish_signup
# authorize! :update, @user
if request.patch? && params[:user] #&& params[:user][:email]
if @user.update(user_params)
@user.skip_reconfirmation!
sign_in(@user, :bypass => true)
redirect_to @user, notice: 'Your profile was successfully updated.'
else
@show_errors = true
end
end
...
我的宝石文件:
source 'https://rubygems.org'
gem 'rails', '3.2.19'
...
gem 'jquery-rails'
gem 'jquery-ui-rails', '~> 5.0.2'
gem 'devise'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
我的用户模型
class User < ActiveRecord::Base
TEMP_EMAIL_PREFIX = 'change@me'
TEMP_EMAIL_REGEX = /\Achange@me/
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
validates_format_of :email, :without => TEMP_EMAIL_REGEX, on: :update
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
attr_accessible :pass, :username, :image, :age
validates :username, :pass, :presence => true
validates :username, :pass, :length => { :minimum => 4 }
validates :username, :uniqueness => true
def self.login(username,pass)
user = find_by_username(username) and user = find_by_pass(pass)
if user.nil?
return nil
else
return user
end
end
def unfollow(other_user)
following_relations.find_by_following_id(other_user.id).destroy
end
def self.search(search)
search_condition = "%" + search + "%"
find(:all, :conditions => ['username LIKE ? OR age LIKE ?', search_condition, search_condition])
end
def self.find_for_oauth(auth, signed_in_resource = nil)
identity = Identity.find_for_oauth(auth)
user = signed_in_resource ? signed_in_resource : identity.user
if user.nil?
email_is_verified = auth.info.email && (auth.info.verified || auth.info.verified_email)
email = auth.info.email if email_is_verified
user = User.where(:email => email).first if email
if user.nil?
user = User.new(
name: auth.extra.raw_info.name,
email: email ? email : "#{TEMP_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com",
password: Devise.friendly_token[0,20]
)
user.skip_confirmation!
user.save!
end
end
if identity.user != user
identity.user = user
identity.save!
end
user
end
def email_verified?
self.email && self.email !~ TEMP_EMAIL_REGEX
end
end
请!帮我解决这个问题或告诉我我的代码有什么问题?
答案 0 :(得分:1)
您需要检查UsersController
文件的位置,放在预期的位置。控制器是复数形式(文件名和类名),你可能在某处有拼写错误。