Rendering a different view depending on model attributes

Is there a good way to render a different view based on a models
attributes? For instance, say there is a model called Form, which
belongs to an Office. And there are 2 offices, say Pre and Post, each
one using a different view, or sharing a view. So say we have the views

form/show.pre.rhtml
form/show.post.rhtml
form/comments.rhtml

So each office has a specific show view, but share a comments view.
Rather than code something that chooses which view to use inside each
action, I’d like that to be done automatically. So say at a later date
I decide to split the comments view separately for each office, I can
just add a new view for each office and it picks the correct one.
Thanks for any help!

Aaron

Would

if @form.office == “Pre”
render :template => “form/show_pre”
else
render :template => “form/show_post”
end

not work? Obviously, youd have to edit those view names to fit there.
[Not
sure that “form/show.pre” wouldn’t have unexpected consequences.]

RSL

Russell N. wrote:

Would

if @form.office == “Pre”
render :template => “form/show_pre”
else
render :template => “form/show_post”
end

not work? Obviously, youd have to edit those view names to fit there.
[Not
sure that “form/show.pre” wouldn’t have unexpected consequences.]

RSL

I could do that, I was just trying to avoid that because I could see
myself repeating myself a lot.

Ah. perhaps write it out into a method and just call the method from the
appropriate places. I wish you could use after_filters to do renders.

RSL