# Conditional show action

**URL:** <https://www.ruby-forum.com/t/conditional-show-action/195511>\
**Category:** Rails\
**Created:** [September 24, 2010, 3:35am UTC](https://www.ruby-forum.com/t/conditional-show-action/195511 "2010-09-24T03:35:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [September 24, 2010, 3:35am UTC](https://www.ruby-forum.com/t/conditional-show-action/195511/1 "2010-09-24T03:35:54Z")

</div>

How can I render a show action on certain conditions?

def show  
@post = Post.find\_approved  
if @post.approved  
approved = true  
end  
respond\_to do |format|  
# I only want to render show.html.erb if approved is true if not I  
would like to redirect the user back to where he came from  
end  
end

---

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [September 24, 2010, 6:40am UTC](https://www.ruby-forum.com/t/conditional-show-action/195511/2 "2010-09-24T06:40:20Z")

</div>

badnaam wrote:

> How can I render a show action on certain conditions?
> 
> def show  
> @post = Post.find\_approved  
> if @post.approved  
> approved = true  
> end  
> respond\_to do |format|  
> # I only want to render show.html.erb if approved is true if not I  
> would like to redirect the user back to where he came from  
> end  
> end

You could do a

respond\_to do |format|  
if approved  
format.html  
end  
end

Is that what you are expecting?

– Raja
