2

I am following the Getting Started with Rails Guide and have made it up to 6.4 when it prompts this code:

$ rails generate controller Comments

My terminal puts this out:

johns-MacBook-Pro:blog john$ rails g controller Comments
/Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:10:in `rescue in execute_if_updated': Rails::Application::RoutesReloader#execute_if_updated delegated to updater.execute_if_updated, but updater is nil: #<Rails::Application::RoutesReloader:0x007faa4156ec60 @paths=["/Users/john/rails/blog/config/routes.rb"], @route_sets=[#<ActionDispatch::Routing::RouteSet:0x007faa41933a30>]> (RuntimeError)
    from /Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
    from /Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
    from /Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
    from /Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/john/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
    from /Users/john/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /Users/john/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
    from /Users/john/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
    from /Users/john/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'
    from /Users/john/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
    from /Users/john/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from /Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
    from /Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/john/rails/blog/config/environment.rb:5:in `<top (required)>'
    from /Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/application.rb:189:in `require'
    from /Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
    from /Users/john/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/commands.rb:45:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'
johns-MacBook-Pro:blog john$ 

I am new to coding and have no idea where to start looking for fix for this.

Here is routes.rb:

Blog::Application.routes.draw do     
  resources :posts

  root to: "welcome#index"
end

resources :posts do
  resources :comments
end
4

1 回答 1

2

欢迎来到 SO 和 Ruby on Rails 的精彩世界:D

看起来你需要搬家

resources :posts do
  resources :comments
end

进入 routes.draw 块

例如/

Blog::Application.routes.draw do     
  resources :posts

  root to: "welcome#index"

  resources :posts do
    resources :comments
  end
end
于 2013-10-31T11:53:48.957 回答