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 %>
Here's the Users controller:
class UsersController < ApplicationController
before_filter :get_开发者_如何学Cuser, :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
And my User model:
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
The exact error I'm getting is this:
ActiveRecord::StatementInvalid in UsersController#create
Could not find table 'users'
P.S.: I'm running Rails 3.1.0.rc8. Any help would be appreciated. Thanks.
UPDATE: I can't seem to find any table. I just upgraded to Rails 3.1, everything was fine before that.
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.
If not, follow Rajkamal's suggestion and make sure you run the migrations.
精彩评论