I have two resources – users and lists, which I want to nest. Everything worked fine, but as soon as i nest lists in users, it throws en error. It works fine on localhost – its just the tests that fails.
This is one of the errors:
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
Any suggestions are much appreciated! Thanks.
I had to update my paths in my app. Instead of
list_path(list), it has to beuser_list_path(user, list)