2
我似乎遇到了我的數據庫問題。我一直在使用Rails創建一個網站,我有一個用戶數據庫。有一個變化,我需要做,所以我耙分貝:下降,現在我看到這個錯誤:耙子中止! NameError:未初始化的常量用戶
這裏是我的用戶控制器:
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
和我目前的用戶數據庫表
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
感謝您給出的任何建議或幫助!
什麼是你的移民文件名? –
20160308001912_users.rb這是我的文件名 – Dan
但是您將遷移類名稱命名爲class CreateUsers