In our application, many resources are nested under a common resource representing an organization. Most URLs include an organization ID the following pattern: /:organization_id/notifications/:id
.
My problem is that I always have to give the current organization to generate the URL to any model. For example, the link to an existing notification would be link_to [@organization, @notification]
.
Since a notification already belongs to an organization, I was wondering if it was possible to generate my URL using link_to @notification
and it would actually generate a URL including the organization ID of the notification. I was hoping that a configuration in the model would be able to achieve this but I could not find anything in the guides, the docs or the source code of Rails.
I would like to keep the organization ID visible in the URL as this is an information that is used by our customers. So I do not want to use shallow nested resources for this problem.
We are using Rails 5.2.0.