我對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