为什么我会收到“找不到表‘用户’"的消息?错误? [英] Why am I getting a "Could not find table 'users'" error?

查看:33
本文介绍了为什么我会收到“找不到表‘用户’"的消息?错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Rails 比较陌生,每次测试登录页面时都会遇到上述错误.这是测试视图文件:

I'm relatively new to Rails and I've been getting the above error whenever I'm testing my login page. Here's the test view file:

<%= 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'

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

P.S.: I'm running Rails 3.1.0.rc8. Any help would be appreciated. Thanks.

更新:我似乎找不到任何表格.我刚刚升级到 Rails 3.1,在那之前一切都很好.

UPDATE: I can't seem to find any table. I just upgraded to Rails 3.1, everything was fine before that.

推荐答案

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

If you have just upgraded to Rails 3.1 and everything was working before the upgrade, check your database.yml configuration. I doubt if the configuration has gone back to the defaults because of the upgrade.

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

If not, follow Rajkamal's suggestion and make sure you run the migrations.

这篇关于为什么我会收到“找不到表‘用户’"的消息?错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆