首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

按照《敏捷开发.》下第一个示例,运行失败

2012-12-31 
按照《敏捷开发..》上第一个示例,运行失败按照《敏捷开发之道 应用Rails进行敏捷开发第二版》上,运行第一个例

按照《敏捷开发..》上第一个示例,运行失败
按照《敏捷开发之道 应用Rails进行敏捷开发第二版》上,运行第一个例子,其他都正常,但是当我添加了say_controller及hello方法后,访问http://localhost/say/hello时,会显示出错,我看了一下development.log里面,有如下的错误,感觉有点不理解,我没用数据库啊,RAILS一定要用数据库吗?如果不是,该如何操作呢?我的rails是2.3.4,ruby是1.8.6,操作系统WINDOWS XP

/!\ FAILSAFE /!\  Sun Oct 04 21:03:03 +0800 2009
  Status: 500 Internal Server Error
  no such file to load -- sqlite3
    D:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    D:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    D:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `require'
    D:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:521:in `new_constants_in'
    D:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `require'
    D:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/kernel/requires.rb:7:in `require_library_or_gem'
    D:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
    D:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/kernel/requires.rb:5:in `require_library_or_gem'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:10:in `sqlite3_connection'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `send'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in `checkout'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `loop'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `checkout'
    D:/Ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in `checkout'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in `connection'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in `retrieve_connection'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `retrieve_connection'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in `connection'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/query_cache.rb:9:in `cache'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/query_cache.rb:28:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'


    D:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/head.rb:9:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/methodoverride.rb:24:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/params_parser.rb:15:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/session/cookie_store.rb:93:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/failsafe.rb:26:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `synchronize'
    D:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/dispatcher.rb:114:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/reloader.rb:34:in `run'
    D:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/dispatcher.rb:108:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/rails/rack/static.rb:31:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:46:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in `each'
    D:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/rails/rack/log_tailer.rb:17:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/content_length.rb:13:in `call'
    D:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/handler/webrick.rb:46:in `service'
    D:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    D:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    D:/Ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    D:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'
    D:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    D:/Ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'
    D:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'
    D:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'
    D:/Ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'
    D:/Ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'
    D:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/handler/webrick.rb:13:in `run'
    D:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/commands/server.rb:111
    D:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    D:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    server:3

[解决办法]
错误是提示,你的数据库未正确配置。配置文件在:config/database.yml 下。默认是用的sqlite3 数据库。你可以配置为你现在在使用中的数据库。
[解决办法]
因为先要初始化connection pool
[解决办法]
config/environment.rb里添加下面两句,就可以不用数据库了

config.action_controller.session = :off
config.frameworks -= [ :active_record, :active_resource, :action_mailer]


[解决办法]
这本书的第二版,用的rails的版本是1.2.6,默认链接的数据库是mysql,但到了rails2.*的版本后,默认链接的数据库就是sqlite3了,建议还是装rails1.2.6来作这本书上的例子,后来一些语法都不一样了,像数据库建表的语法:t.column :name, :string (rails1.2) / t.string :name (rails2.0)。
如果你是Windows下做这本书上的例子,在那个products表里增加一个price字段时,还会遇到系统对浮点数计算的问题,rake的时候会报错的!
[解决办法]
http://pragprog.com/titles/rails3/source_code
下载最新的代码,这样可以保证你跑程序非常顺利

热点排行