0

I have this in my routes.rb

resources :users, :path => "/", :only => [:show] do
  resources :collections, :controller => 'users/collections'
end

Why can I access to collections resources from:

http://localhost:3000/en/collections

if this resouce this inside users?

I want that collection resource only is enable inside:

http://localhost:3000/en/users/collections

This is my routes:

user_collections GET    (/:locale)/:user_id/collections(.:format)          users/collections#index
                         POST   (/:locale)/:user_id/collections(.:format)          users/collections#create
     new_user_collection GET    (/:locale)/:user_id/collections/new(.:format)      users/collections#new
    edit_user_collection GET    (/:locale)/:user_id/collections/:id/edit(.:format) users/collections#edit
         user_collection GET    (/:locale)/:user_id/collections/:id(.:format)      users/collections#show
                         PUT    (/:locale)/:user_id/collections/:id(.:format)      users/collections#update
                         DELETE (/:locale)/:user_id/collections/:id(.:format)      users/collections#destroy

How can I do it?

Thank you

hyperrjas
  • 10,666
  • 25
  • 99
  • 198
  • Did you restart your app after changing your routes? – jdoe Jun 04 '12 at 17:26
  • Yes, I have restarted my server after changing routes. I'm using rails 3.2. – hyperrjas Jun 04 '12 at 17:28
  • do you need that :path => "/" ? – Anil Jun 04 '12 at 17:30
  • This is the problem, if I remove `:path => "/"` My url is very long. I have now `http://localhost:3000/en/kevin29/collections` but If I remove `:path => "/"` I have this: `http://localhost:3000/en/users/kevin29/collections` I want remove the `users` prefix! – hyperrjas Jun 04 '12 at 17:35
  • Are you sure accessing `/en/collections` triggers collections#index? I think it has to trigger users#show, passing the string `collections` as id in params. – jdoe Jun 04 '12 at 17:39
  • Yes I understand, but I have not an user named **collection** in my db. I must get an error... if the user collection is not found in database... – hyperrjas Jun 04 '12 at 17:46
  • Show us the `params` from your log during accessing `/en/collections` – jdoe Jun 04 '12 at 17:55
  • Sorry for delay @jdoe. The params `--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess action: index controller: users/collections user_id: en` the problem is that `en` is taken as a `user_id`. How can I fix this problem? Thank you! – hyperrjas Jun 05 '12 at 17:49

1 Answers1

0

Try this:

resources :users, :only => [:show] do
  resources :collections, :controller => 'users/collections'
end
Anil
  • 3,899
  • 1
  • 20
  • 28
  • With this solution I have a long url sth like: `http://localhost:3000/en/users/kevin29/collections` I want this url `http://localhost:3000/en/kevin29/collections` Thank you! – hyperrjas Jun 04 '12 at 17:39