2014-11-17 52 views
0

我用設計來連接Twitter和Facebook,和我有兩個問題: 當我的Runn我的應用程序:路由錯誤時制定

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 
... 

我的Gemfile:

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 = '[email protected]' 
    TEMP_EMAIL_REGEX = /\[email protected]/ 
    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 

請!幫我解決這個問題,或者告訴我我的代碼有什麼問題?

回答

1

你需要檢查你的UsersController文件的位置,放在預期的地方。和控制器是複數形式(文件名和類名),你可能有錯別字。

+0

是啊!我在控制器中使用了不同的用戶名,我很傻:))謝謝你 – mayoneQD