我正在尝试通过Michael Hartl Rails Tutorial并在我尝试注册后立即遇到错误链接-reference- Rails Tutorial Signup:
在UsersController #new
中的ActiveRecord :: StatementInvaliddef table_structure(table_name)
structure = exec_query("PRAGMA table_info(#{quote_table_name(table_name)})", 'SCHEMA').to_hash
**raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty?**
structure
end
在第7.2节末尾,说明是删除在6.3.4节中创建的用户
$ bundle exec rake db:migrate:reset
这与无法找到桌子有关吗?任何帮助,将不胜感激。感谢
我的schema.rb文件只包含:
ActiveRecord::Schema.define(version: 0) do
端
这是我的user.rb文件:
class User < ActiveRecord::Base
before_save { self.email = email.downcase }
validates:name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates:email, presence: true, length: { maximum: 50 },
format: {with: VALID_EMAIL_REGEX},
uniqueness: {case_sensitive: false}
has_secure_password
validates :password, presence: true, length: {minimum: 6}
end
这是完整的错误跟踪:
app/controllers/users_controller.rb:9:in `new'
activerecord (4.2.2) lib/active_record/connection_adapters/sqlite3_adapter.rb:511:in `table_structure'
activerecord (4.2.2) lib/active_record/connection_adapters/sqlite3_adapter.rb:385:in `columns'
activerecord (4.2.2) lib/active_record/connection_adapters/schema_cache.rb:43:in `columns'
activerecord (4.2.2) lib/active_record/attributes.rb:93:in `columns'
activerecord (4.2.2) lib/active_record/attributes.rb:98:in `columns_hash'
activerecord (4.2.2) lib/active_record/inheritance.rb:205:in `subclass_from_attributes?'
activerecord (4.2.2) lib/active_record/inheritance.rb:54:in `new'
actionpack (4.2.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.2) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.2) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.2) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.2) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.2) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.2) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.2) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.2) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.2) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.2) lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
activesupport (4.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.2) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.2) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.2) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.2) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.2) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.2) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.2) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.2) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.2) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.2) lib/action_dispatch/routing/route_set.rb:74:in `call'
actionpack (4.2.2) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
actionpack (4.2.2) lib/action_dispatch/routing/route_set.rb:43:in `serve'
actionpack (4.2.2) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.2) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.2) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.2) lib/action_dispatch/routing/route_set.rb:819:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.2) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.2) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.2) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
activerecord (4.2.2) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.2) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.2) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.2) lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
activesupport (4.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.2) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.2) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call'
web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:13:in `call'
actionpack (4.2.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.2) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.2) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.2) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.2) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.2) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.2) lib/rails/engine.rb:518:in `call'
railties (4.2.2) lib/rails/application.rb:164:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
答案 0 :(得分:2)
无论出于何种原因,您的users
表不再存在,这就是您收到该错误消息的原因。
执行以下操作:
# drop the database first
bundle exec rake db:reset
# This will create the database, load the schema, and initialize with the seed data
bundle exec rake db:setup
# run the pending migrations if any
bundle exec rake db:migrate
让我们从头开始重新创建用户模型。
首先,让我们在重新创建之前清理用户模型的混乱。:
rails destroy model User
然后运行:
rails generate model User name:string email:string
下一步:
bundle exec rake db:migrate