1

我正在尝试为以前的开发人员传给我的 ROR 应用程序设置本地开发环境。我是 ROR 和 Ruby 的新手。

首先我运行bundle install没有问题,然后mongod。当我运行rails s服务器启动时,它会输出host is not a valid option for Mongo::Connection.

当我尝试转到时http://0.0.0.0:3000出现错误消息。 NoMethodError in Home#index

错误指向以下路径:

显示 /Users/ryansnyder/Rails/myAppX/app/views/home/index.html.haml 其中第 12 行提出:

undefined method 'url' for nil:NilClass

提取的源代码(第 12 行附近):

9:     %h2 Asset Protection
10:     = link_to image_tag('asset-protection-guide.png'), 'http://myAppX.s3.amazonaws.com/assets/downloads/myAppX-AssetProtectionGuide.pdf', :title => 'Asset Protection Guide', :alt => 'Download our Asset Protection Guide', :target => '_blank'
11:   %section#graphs
12:     = link_to image_tag(@chart.url, :alt => @chart.alt), eval(@chart.link), :title => @chart.title
13: 
14: %section#recent-happenings
15:   %section#upcoming-events

我在 .haml 文件中注释掉了该行,然后刷新http://0.0.0.0:3000并收到另一个undefined method 'question' for nil:NilClass错误。我认为这是数据库或错误处理问题。但我只是猜测。

编辑:我不知道这是否有帮助,但是在运行时rake test我收到以下输出。

host is not a valid option for Mongo::Connection
/Users/ryansnyder/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.19/lib/active_support/dependencies.rb:242:in `require': no such file to load -- turn (LoadError)
    from /Users/ryansnyder/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.19/lib/active_support/dependencies.rb:242:in `block in require'
    from /Users/ryansnyder/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.19/lib/active_support/dependencies.rb:227:in `load_dependency'
    from /Users/ryansnyder/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.19/lib/active_support/dependencies.rb:242:in `require'
    from /Users/ryansnyder/Rails/alerstallings-master/test/test_helper.rb:4:in `<top (required)>'
    from /Users/ryansnyder/Rails/alerstallings-master/test/functional/lawyers_controller_test.rb:1:in `require'
    from /Users/ryansnyder/Rails/alerstallings-master/test/functional/lawyers_controller_test.rb:1:in `<top (required)>'
    from /Users/ryansnyder/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:10:in `require'
    from /Users/ryansnyder/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /Users/ryansnyder/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:9:in `each'
    from /Users/ryansnyder/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /Users/ryansnyder/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/ryansnyder/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:4:in `<main>'
Errors running test:functionals!

编辑 2:mondoid.yml

defaults: &defaults
  host: localhost
  # slaves:
  #   - host: slave1.local
  #     port: 27018
  #   - host: slave2.local
  #     port: 27019

development:
  <<: *defaults
  database: alerstallings_development

test:
  <<: *defaults
  database: alerstallings_test

staging:
  uri: <%= ENV['MONGOHQ_URL'] %>

# set these environment variables on your prod server
production:
  uri: <%= ENV['MONGOHQ_URL'] %>

任何帮助,将不胜感激。

4

1 回答 1

0

您需要检查您要返回的对象是否不为零。您应该添加一些错误处理并检查您的数据库是否返回了适当的对象。一个快速的解决方法是有条件地运行您的代码:

unless @chart.nil?
  # Your previous code here
end
于 2013-02-25T20:20:52.883 回答