Mysql 为什么我会得到一个“a”;找不到表';用户'&引用;错误?
我对Rails比较陌生,每次测试登录页面时都会遇到上述错误。 以下是测试视图文件:Mysql 为什么我会得到一个“a”;找不到表';用户'&引用;错误?,mysql,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.1,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 %&g
<%= 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 %>
注意:我正在运行Rails 3.1.0.rc8。任何帮助都将不胜感激。谢谢
更新:我似乎找不到任何表格。我刚升级到Rails 3.1,在此之前一切都很好。如果您刚升级到Rails 3.1,并且在升级之前一切正常,请检查您的
数据库.yml
配置。我怀疑配置是否因为升级而恢复到默认值
如果没有,请遵循Rajkamal的建议并确保运行迁移。是否在应用程序根目录上运行了rake db:migrate命令?是的,但它不起作用。我只是检查了我的database.yml文件,一切都与以前完全一样。可能是我用的是mysql而不是mysql2吗?是的。。检查您的Gemfile,如果您已经安装了mysql2 gem,那么适配器应该是mysql2I。我刚刚在Gemfile和database.yml文件中将mysql更改为mysql 2,并且在运行“bundle install”时,我在安装mysql2时出错:
安装mysql2(0.3.7)使用本机扩展C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:552:在构建中的块中进行救援_扩展:错误:未能构建gem本机扩展。(Gem::Installer::ExtensionBuildError)
我无法在Windows上安装mysql2。也许你可以帮忙?我需要在运行时指定一些参数:gem install mysql2。请添加关于如何解决创建问题的解决方案,以便其他人在遇到相同问题时可以参考你的问题。在CMD中运行railsdbconsole时,键入showtables代码>您看到它找不到的表了吗?通过rake db:migrate
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'