I have about 5 models that behave very similarly. In fact, I'd like them to share an action for displaying them. For example, for models Car, Truck, Van I want to have a definition like:
[Car, Truck, Van].each do |Model|
action_for Model do #I made this up to show what I mean
def index
@model = Model.all
@model_names = @model.map(&:name).join(', ')
end
end
end
How would I do this so I'm not defining the same action in multiple controllers? (Which isn't very DRY) Would it be in the application_controller? And if it's not too much to ask, how could I do this so they also share the view?
UPDATE
It would be preferred if this can be outside the individual controllers. If I can get this to work right, I'd like to not even have to generate the individual controllers.