0

我有两个资源——用户和列表,我想嵌套它们。一切正常,但是一旦我在用户中嵌套列表,它就会引发错误。它在本地主机上运行良好 - 它只是失败的测试。

这是错误之一:

  1) Authentication signin with valid information 
     Failure/Error: before { sign_in user }
     ActionView::Template::Error:
       undefined method `lists_path' for #<#<Class:0x007fecbd7812f0>:0x007fecbad265a0>
     # ./app/views/shared/_create_list.html.erb:2:in `_app_views_shared__create_list_html_erb___4033534818329635871_70327383327980'
     # ./app/views/users/show.html.erb:17:in `_app_views_users_show_html_erb___4510442023060893439_70327361676640'
     # (eval):2:in `click_button'
     # ./spec/support/utilities.rb:7:in `sign_in'
     # ./spec/requests/authentication_pages_spec.rb:32:in `block (4 levels) in <top (required)>'

路线.rb

MyApp::Application.routes.draw do
  resources :users do
    resources :lists, only: [:show, :create, :destroy]
  end
  resources :items, only: [:show, :create, :destroy]
  resources :sessions, only: [:new, :create, :destroy]

列表.rb

class List < ActiveRecord::Base
  attr_accessible :name
  belongs_to :user
  has_many :items, dependent: :destroy

  validates :name, presence: true, length: { maximum: 60 }
  validates :user_id, presence: true
end

用户.rb

class User < ActiveRecord::Base
  attr_accessible :name, :email, :password, :password_confirmation
  has_secure_password
  has_many :lists, dependent: :destroy
  has_many :items, through: :lists

任何建议都非常感谢!谢谢。

4

1 回答 1

0

我必须在我的应用程序中更新我的路径。而不是list_path(list),它必须是user_list_path(user, list)

于 2012-12-21T08:05:54.973 回答