我有两个资源 - 用户和列表,我想要嵌套。一切都运行良好,但只要我在用户中嵌套列表,它就会引发错误。它在localhost上工作正常 - 它只是失败的测试。
这是其中一个错误:
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)>'
routs.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]
list.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
user.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
非常感谢任何建议!感谢。
答案 0 :(得分:0)
我必须在我的应用中更新路径。而不是list_path(list)
,它必须是user_list_path(user, list)