使用ROR运行命令rake routes
时出现以下错误。
错误:
NoMethodError: undefined method `resources' for nil:NilClass
C:/Sites/bookshelf/config/routes.rb:4:in `block (2 levels) in <top (required)>'
C:/Sites/bookshelf/config/routes.rb:3:in `block in <top (required)>'
C:/Sites/bookshelf/config/routes.rb:1:in `<top (required)>'
C:in `execute_if_updated'
C:/Sites/bookshelf/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => routes => environment
(See full trace by running task with --trace)
我正在解释下面的代码。
Rails.application.routes.draw do
root 'books#index'
resources :books do |book|
book.resources :comments, :only => :create
end
end
请帮我解决此错误。
答案 0 :(得分:2)
Rails.application.routes.draw do
root 'books#index'
resources :books do
resources :comments, :only => :create
end
end