我对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,在此之前一切都很好。
你在应用程序根目录上运行rake db:migrate命令吗? – rajkamal
是的,我有,但它没有奏效。 – Sam