[英]How to define routing concern in rails
如何定義rails路由關注
我有用戶和消息的附件。 我怎樣才能定義共同的路線
resources :comments
用戶和消息控制器的路由
resources :users
resources :messages
根據文檔 ,您需要:
#config/routes.rb
concern :attachment do
resources :attachment, only: :index
end
resources :users, :messages, concerns: :attachment
據我了解你的問題,你有一個用戶和消息的附件,需要一個更干的方式為此創建路由。 我們可以為此目的使用顧慮。
concern :attachable do
resource: :attachment #singular routes
end
resources :users, :messages, concerns: :attachable
我使用了單數路由,因為我假設附件和用戶/消息之間存在has_one關系。 也就是說,用戶has_one附件或消息has_one附件。 如果它是has_many關系,請使用多個路由,即
resources: :attachments
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.