rake aborted! NameError: uninitialized constant Users
rake aborted! NameError: uninitialized constant Users
我的数据库似乎 运行 出了问题。我一直在使用 Rails 创建一个网站,并且我有一个用户数据库。我需要做一些改变,所以我耙 db:drop 现在我看到这个错误:
这是我的用户控制器:
class UsersController < ApplicationController
def new
@user = User.new
end
def show
@user = User.find(params[:id])
end
def create
@user = User.new(user_params)
if @user.save
session[:user_id] = @user.id
redirect_to @user
else
render 'new'
end
end
private
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :phone_number, :address_one, :address_two, :city, :country, :state, :zip)
end
end
我的用户模型:
class User < ActiveRecord::Base
has_secure_password
validates :email, presence: true
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.id).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.password = "a"
user.email = user.uid
user.save!
end
end
end
和我当前的用户数据库 table
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :first_name
t.string :last_name
t.string :email
t.string :password_digest
t.string :phone_number
t.string :address_one
t.string :address_two
t.string :city
t.string :country
t.string :state
t.string :zip
end
end
end
感谢您提供的任何建议或帮助!
迁移文件名和class 名称应该相同。两者需要保持一致才能rails动态加载合适的class.
class CreateUsers < ActiveRecord::Migration
改为 class Users < ActiveRecord::Migration
运行 rake db:migrate
我的数据库似乎 运行 出了问题。我一直在使用 Rails 创建一个网站,并且我有一个用户数据库。我需要做一些改变,所以我耙 db:drop 现在我看到这个错误:
这是我的用户控制器:
class UsersController < ApplicationController
def new
@user = User.new
end
def show
@user = User.find(params[:id])
end
def create
@user = User.new(user_params)
if @user.save
session[:user_id] = @user.id
redirect_to @user
else
render 'new'
end
end
private
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :phone_number, :address_one, :address_two, :city, :country, :state, :zip)
end
end
我的用户模型:
class User < ActiveRecord::Base
has_secure_password
validates :email, presence: true
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.id).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.password = "a"
user.email = user.uid
user.save!
end
end
end
和我当前的用户数据库 table
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :first_name
t.string :last_name
t.string :email
t.string :password_digest
t.string :phone_number
t.string :address_one
t.string :address_two
t.string :city
t.string :country
t.string :state
t.string :zip
end
end
end
感谢您提供的任何建议或帮助!
迁移文件名和class 名称应该相同。两者需要保持一致才能rails动态加载合适的class.
class CreateUsers < ActiveRecord::Migration
改为 class Users < ActiveRecord::Migration
运行 rake db:migrate