# ActionView::Base - can it dynamically select views?

**URL:** <https://www.ruby-forum.com/t/actionview-base-can-it-dynamically-select-views/189942>\
**Category:** Rails\
**Created:** [June 10, 2010, 10:11am UTC](https://www.ruby-forum.com/t/actionview-base-can-it-dynamically-select-views/189942 "2010-06-10T10:11:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Owain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@Owain](https://www.ruby-forum.com/u/Owain)\
**Post date:** [June 10, 2010, 10:11am UTC](https://www.ruby-forum.com/t/actionview-base-can-it-dynamically-select-views/189942/1 "2010-06-10T10:11:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Owain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@Owain](https://www.ruby-forum.com/u/Owain)\
**Post date:** [June 12, 2010, 12:15pm UTC](https://www.ruby-forum.com/t/actionview-base-can-it-dynamically-select-views/189942/2 "2010-06-12T12:15:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Owain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@Owain](https://www.ruby-forum.com/u/Owain)\
**Post date:** [June 12, 2010, 12:35pm UTC](https://www.ruby-forum.com/t/actionview-base-can-it-dynamically-select-views/189942/3 "2010-06-12T12:35:53Z")

</div>

On 12 June 2010 11:14, Owain [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
