Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord::StatementInvalid: Could not find table 'users'

I am learning Ruby on Rails Tutorial, I have finished the chapter 7 and it works well, but come across 25 failures/errors like the following:

User Failure/Error: @user = User.new(name: "Example User", email: "[email protected]", ActiveRecord::StatementInvalid: Could not find table 'users' # ./spec/models/user_spec.rb:18:in new' # ./spec/models/user_spec.rb:18:inblock (2 levels) in '

This is the users_controller.rb

class UsersController < ApplicationController
  def new
    @user = User.new
  end

  def show
    @user = User.find(params[:id])
  end

  def create
    @user = User.new(params[:user])
    if @user.save
      flash[:success] = "Welcome to the Sample App!"
      redirect_to @user
    else
      render 'new'
    end
  end
end

Thanks for your help.

like image 488
Yang Wen Avatar asked May 13 '12 04:05

Yang Wen


1 Answers

You can check to see if db/test.sqlite3 is empty. In that case, run rake db:test:prepare

like image 88
hintt Avatar answered Oct 14 '22 18:10

hintt