未定义的局部变量或方法'book'

时间:2016-10-02 14:24:52

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4

我是rails的新手并尝试创建示例应用。我有

应用/ routes.rb中

Rails.application.routes.draw do 
     resources :books do
        book.resources :comments, :only => :create
     #root 'books#index'
end
end

不确定我为什么会收到以下错误

/bookshelf/config/routes.rb:3:in `block (2 levels) in <top (required)>': undefined local variable or method `book' for #<ActionDispatch::Routing::Mapper:0x007fdebb03e728> (NameError)

1 个答案:

答案 0 :(得分:2)

删除“book。”

应该看起来像:

Rails.application.routes.draw do 
  resources :books do
    resources :comments, only: :create
  end
end