# Render view depending on state

**URL:** <https://www.ruby-forum.com/t/render-view-depending-on-state/127051>\
**Category:** Rails\
**Created:** [January 24, 2008, 4:43pm UTC](https://www.ruby-forum.com/t/render-view-depending-on-state/127051 "2008-01-24T16:43:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [January 24, 2008, 4:43pm UTC](https://www.ruby-forum.com/t/render-view-depending-on-state/127051/1 "2008-01-24T16:43:05Z")

</div>

Hi all,

I have a list of events and when clicked an event you get detailed  
info of the event. The detailed info actually depends on whether the  
event has already occured or not. So if the event still has to happen  
different content has to be rendered.

Is there a rails way on dealing with this or do I just use (in event/  
show.html.erb):

if @event.starttime \< Time.now  
#render event way 1  
else  
#render event way 2  
end

Thanks in advance  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [January 24, 2008, 5:07pm UTC](https://www.ruby-forum.com/t/render-view-depending-on-state/127051/2 "2008-01-24T17:07:18Z")

</div>

On Jan 24, 2008, at 9:42 AM, Tarscher wrote:

> if @event.starttime \< Time.now  
> #render event way 1  
> else  
> #render event way 2  
> end

You can do at least three ways:

1. make the decision in the controller and render one of two views with

render :template =\> ‘path\_to/template’

1. make the decision in a template and render one of two partials

\<% if @event.starttime \< Time.now %\>  
\<%= render :partial =\> ‘past\_event’ %\>  
\<% else %\>  
\<%= render :partial =\> ‘future\_event’ %\>  
\<% end %\>

1. As you said, make the decision in the template and put all  
rendering in the one file.

Personally, I’d probably go with #2.

Peace,  
Phillip
