0

The following path throws up an error:

 = link_to 'Subscribers', user_subscribers_path(current_user)

undefined method `user_subscribers_path' for <#:0x007f9b240b3148>

I am not sure why.

I have defined my routes as follows:

  resources :users, :only => [:show, :index], :has_many => :subscribers, :shallow => true

Thanks!

EDIT rake routes does not show anything particularly useful. The only two lines with subscribers are:

users GET    /users(.:format)               users#index {:has_many=>:subscribers}
user GET    /users/:id(.:format)           users#show {:has_many=>:subscribers}
1
  • Can you do rake routes in your terminal and show us the result? Commented Sep 11, 2012 at 18:05

1 Answer 1

1

You need to define resource subscribers in routes files as follows

resources :users do 
 resources :subscribers
end

this will create the needed path helper for your resource

For the shallow routes you can use

 map.resources :users, :shallow => true do |user|
  user.resources :subscribers 
 end
Sign up to request clarification or add additional context in comments.

4 Comments

I want my routes to be shallow. I guess I would have to define shallow here?
and that seems to define routes like new_subscriber GET/subscribers/new(.:format) subscribers#new - which is probably something I would not be interested since I am looking for nested routes ...
this will create nested routes, you can create shallow routes by passing :shallow=> true to helper. check this out archives.ryandaigle.com/articles/2008/9/7/…
worked. I simply added what you added above with the :shallow. I have marked your answer as fixed - would be great if you updated your answer with :shallow for future reference and other users. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.