Łukasz Korol Łukasz Korol - 7 months ago 12
Ruby Question

How to name route link?

I have a problem with adding name to route link.
Below there is screen of routing:
enter image description here

I want to name last link:

GET /backend/people/:id/vacations/new(.:format)


What I tried:

resources :vacations, only: [:new, :create] do
collection do
get 'new', as: 'people_vacation'
end
end


Unfortunately this code duplicates new action.
enter image description here

How to avoid this duplication and have only one link(with name) to new action?

Answer

I guess you should update your definition to:

resources :vacations, only: [:create] do
  collection do
    get 'new', as: 'people_vacation'
  end
end

This way, "new" action won't be replicated