简体   繁体   English

尝试设计时出现路由错误

[英]Routing Error when trying devise

I'm using devise to connect twitter and facebook, and i have two problem : when i runn my app: 我正在使用devise连接Twitter和Facebook,但是我有两个问题:当我运行我的应用程序时:

http://localhost:3000/users/10/finish_signup

i have first problem: 我有第一个问题:

LoadError in UserController#finish_signup
Expected ../app/controllers/user_controller.rb to define UserController

When i reload this link, i have second problem: 当我重新加载此链接时,我遇到第二个问题:

Routing Error
uninitialized constant UserController

Here, my routes: 在这里,我的路线:

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

My user_controller 我的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
...

My gemfile: 我的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'

My user model 我的用户模型

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

Please! 请! help me to fix that or tell me what problem of my code?? 帮我解决这个问题,或者告诉我代码有什么问题??

You need to check where your UsersController file is, put in expected place. 您需要检查UsersController文件的位置,放在预期的位置。 And controller is in plural form (both file name and class name), you may have typos somewhere. 并且控制器为复数形式(文件名和类名),您可能在某处输入错字。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM