I am looking for best practice to solve the following situation:
I have an “additive” model, which should be many-to-many, related to some other models.
Examples:
# Meal-Model has_and_belongs_to_many :additives # Offer-Model has_and_belongs_to_many :additives # Additive-Model has_and_belongs_to_many :meals has_and_belongs_to_many :meals
Routes are nested as follows:
resources :offers do resources :additives end resources :meals do resources :additives end
So, I get the urls like this:
/offers/123/additives /meals/567/additives
Both routes lead to the same controller action as additives#index . In AdditivesController, I check to see if options are available to select the data to retrieve:
class AdditivesController < ApplicationController before_filter :offermealswitch
Is this the right way to deal with this problem? It works very well, but I'm not sure if these are rails ... Thanks for your answers!
source share