如何命名路由链接?

时间:2016-05-05 10:20:25

标签: ruby-on-rails ruby

我在为路线链接添加名称时遇到问题。 下面是路由屏幕: enter image description here

我想命名最后一个链接:

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

我尝试了什么:

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

不幸的是,此代码重复了新操作。 enter image description here

如何避免这种重复,并且只有一个链接(带名称)到新操作?

1 个答案:

答案 0 :(得分:6)

我想你应该将你的定义更新为:

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

这样," new"行动不会被复制