I seem to have run into a problem with my database. I have been using Rails to create a website and I have a database for Users. There was a change I needed to make so I rake db:drop and now I see this error:
database issue
Here is my users controller:
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
my user model:
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
and my current users database 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
Thanks for the any advice or help given!
The migration filename and class name should be same. The two need to be consistent for rails to dynamically load the appropriate class.
class CreateUsers < ActiveRecord::Migration
change it to class Users < ActiveRecord::Migration
Run rake db:migrate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With