Prezes Łukasz
Prezes Łukasz

Reputation: 968

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?

Upvotes: 2

Views: 86

Answers (1)

Emiliano Della Casa
Emiliano Della Casa

Reputation: 916

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

Upvotes: 6

Related Questions