0

I have some routes like this:

resources :users do
  member do
    get 'services', :path => 'services/edit', :defaults => { :servicable => 'user' }
  end
end

This allows me to have localhost:3000/users/1/services/edit

I'm trying to add dynamic path to it.

I tried adding :as => :edit_services_path

get 'services', :path => 'services/edit', :defaults => { :servicable => 'user' }, :as => :edit_services_path

so I can try something like this:

<%= link_to "Edit", edit_services_path %>

But it gives me error.

undefined local variable or method `edit_services_path' for #<#<Class:0x007f856fd5a970>:0x007f856ff18690>

I tried searching what the correct way of adding a new path if I'm customizing my path, but haven't had any luck,

Thanks

hellomello
  • 8,219
  • 39
  • 151
  • 297

1 Answers1

1

Using the method you specify does yield a dynamic path, just not the one you are trying to use. It yields :

services_user GET    /users/:id/services/edit(.:format)                users#services {:servicable=>"user"}

And adding the :as option creates:

edit_services_path_user GET    /users/:id/services/edit(.:format)                users#services {:servicable=>"user"}

Which is a bit confusing, since usually path is not specified in the path, but used as a helper on the route itself (i.e. services_user path would be services_user_path with the path helper) so if the naming maters a lot to you this can be finessed but it is generating the dynamic paths, you can use rake routes to view these as you change things as well.

Community
  • 1
  • 1
Jay Truluck
  • 1,509
  • 10
  • 17
  • Ohhhh thanks!! Yeah I was using `rake routes` but I couldn't find `services_user` until you said it and I was looking for it, Thanks! – hellomello Jun 27 '13 at 05:39