ActionView::Base - can it dynamically select views?

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:

  1. 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.
  2. 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!
  3. 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?
  4. Am I re-inventing the wheel and there is already a plugin or
    something to do this?

Thanks for your help.

O.

There has been no suggestions on this. Perhaps the question was not
very well explained?

I have a model called Product that has an attribute called
product_type. I have another model called Quote which creates a quote
for a Product. Quote belongs to Product. And a QuoteController.

How do I get the QuoteController to use a different view for its
actions dependent upon the product_type? In general most
product_types will use the “normal” set of views for a quote so it
would be excellent if the QuoteController was able to use the specific
product_type views if they exist and if not fall back to the default
set.

Further thinking in the OP below.

Any ideas gratefully received.

O.

On 12 June 2010 11:14, Owain [email protected] wrote:

would be excellent if the QuoteController was able to use the specific
product_type views if they exist and if not fall back to the default
set.

In the controller you can use render to show whatever view you like,
just test your product type and render the appropriate view.

Colin