为什么我收到“无法找到表'用户'”错误?

时间:2011-08-31 07:31:31

标签: mysql ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1

我对Rails相对较新,每当我测试登录页面时,我都会遇到上述错误。 这是测试视图文件:

<%= form_for :user, :url => create_path do |f| %>
  <p> Email: <br />  <%= f.text_field :email %></p>
  <p> Password: <br />  <%= f.password_field :password %></p>
  <p><%= submit_tag "Sign In", :disable_with => "Please wait...", :class => "btn primary" %></p>
<% end %>

这是用户控制器:

class UsersController < ApplicationController   
  before_filter :get_user, :except => [:register, :login, :create]
  before_filter :user_signed_in?, :only => [:delete]

  def create
    if user = User.find_by_email(params[:user][:email]).try(:authenticate, params[:user][:password])
      session[:user_id] = user.id
      redirect_to root_path # Or whatever you want i.e. redirect_to user
    else
      render :new, :flash => { :error => "Bad email/password combination" }
    end
  end

  def delete
    session.delete(:user_id)
  end

  def register
    if Invite.find_by_hash(params[:hash]).blank?
      redirect_to root_path
      return
    end
    @user = User.new(params[:user])
    if(request.post? and @user.save)
      flash[:notice] = "Account Created Successfully"
      redirect_to root_path      
      return
    else
      flash.now[:warning] = @user.errors.full_messages
    end
  end

  def destroy
    @user = User.find(params[:id])
    @user.destroy
    redirect_to root_path
  end

  def login

  end

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

end

我的用户模型:

class User < ActiveRecord::Base
  has_secure_password
  validates :email, :presence => true, :uniqueness => true, :length => {:minimum => 6}
  validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
  validates :name, :presence => true, :length => {:maximum => 32}
  validates :password, :presence => true, :length => {:minimum => 8}
  validates :username, :presence => true, :length => {:maximum => 20}, :uniqueness => true
  validates :blog, :uniqueness => true
  has_many :posts
end

我得到的确切错误是:

ActiveRecord::StatementInvalid in UsersController#create
Could not find table 'users'

P.S。:我正在运行Rails 3.1.0.rc8。任何帮助,将不胜感激。感谢。

更新:我似乎无法找到任何表格。我刚刚升级到Rails 3.1,之前一切都很好。

1 个答案:

答案 0 :(得分:1)

如果您刚刚升级到Rails 3.1并且在升级之前一切正常,请检查您的database.yml配置。我怀疑由于升级,配置是否已恢复为默认值。

如果没有,请遵循Rajkamal的建议并确保您运行迁移。