There are some similar discussions about but none seem to have a
definitive answer of this one.
I have an application which supports multiple domains. In the
application controller I look up the domain being requested and pull
some attributes from a Domain model which determines thing such as
content wording, pricing model, which css to use etc. All works fine
but a new domain in the “family” needs to have a different “Quote”
data entry from the other domains (domain_type). Ok MVC, this is
where you need to do your stuff. M is unchanged. C has a slight
tweek (pull in some select box data prior to rendering the form) and
only really the View needs any changes.
What I would like to do is to have ActionView to see if there is a
domain specific view in app/views/quote/domain_type and render that,
if it isn’t there then just pull it from the app/views/quote (i.e. the
else)
Options I have considered are:
- put the domain_type logic in each effected views, not very DRY and
horrible to add new domain_types. Also this is really Controlller
logic. - code a “custom render” logic into the controller or application
controller to render the appropriate file, ok but need to go through
and change all of the coded and implied renders in the application.
Yuk! - override render method of ActionView::Base to pick up the
@domain.domain_type and code the logic in the overidden method and
then call super. Best method but not sure how to do this? - Am I re-inventing the wheel and there is already a plugin or
something to do this?
Thanks for your help.
O.