Reputation: 61
I'm using devise to connect twitter and facebook, and i have two problem : when i runn my app:
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
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:
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??
Upvotes: 0
Views: 117
Reputation: 9959
You need to check where your UsersController
file is, put in expected place. And controller is in plural form (both file name and class name), you may have typos somewhere.
Upvotes: 1