# Conditionals in the view based on a requested format

**URL:** <https://www.ruby-forum.com/t/conditionals-in-the-view-based-on-a-requested-format/129597>\
**Category:** Rails\
**Created:** [February 19, 2008, 11:57pm UTC](https://www.ruby-forum.com/t/conditionals-in-the-view-based-on-a-requested-format/129597 "2008-02-19T23:57:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [February 19, 2008, 11:57pm UTC](https://www.ruby-forum.com/t/conditionals-in-the-view-based-on-a-requested-format/129597/1 "2008-02-19T23:57:00Z")

</div>

i am using respond\_to for a few actions in my controller. for some of  
the actions, the view for html and the view for javascript would be  
nearly identical.

what can i do in my views to hide or add content based on whether  
there was an ajax request or not?

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [February 20, 2008, 8:02pm UTC](https://www.ruby-forum.com/t/conditionals-in-the-view-based-on-a-requested-format/129597/2 "2008-02-20T20:02:34Z")

</div>

Why not just set an instance variable on the controller within the  
respond\_to block and then conditionally render within the view based  
on it’s value?
