铁路路由;路径改变收集

时间:2016-01-11 23:26:15

标签: ruby-on-rails routing

目前我的other_notifications / chat_notificaitons的路线是:

/users/:id/notifications/chat_notifications

但我希望如此:

/users/1/chat_notifications

我该怎么做?如果我改变这样的路线,有什么问题需要注意吗?

的routes.rb

resources :users do
  resources :notifications, only: [:create, :index] do
    collection do
      get :other_notifications, :chat_notifications
    end
  end
end

1 个答案:

答案 0 :(得分:1)

试试这个:

resources :users do
  resources :notifications, only: [:create, :index] 
end
get 'users/:user_id/chat_notifications', to: 'controllerName#actionName', as: :custom_name