# changing format (for respond\_to)

**URL:** <https://discuss.rubyonrails.org/t/changing-format-for-respond-to/58612>\
**Category:** rubyonrails-talk\
**Created:** [April 23, 2011, 6:31am UTC](https://discuss.rubyonrails.org/t/changing-format-for-respond-to/58612 "2011-04-23T06:31:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [April 23, 2011, 6:31am UTC](https://discuss.rubyonrails.org/t/changing-format-for-respond-to/58612/1 "2011-04-23T06:31:03Z")

</div>

So in my action I have:

- respond\_to do |format| - format.html - format.iphone - end

Now I can access action.html and action.iphone, however how would I make it default to the iPhone view if the user agent is an iPhone. I'm pretty tired so forgive me for being brief or perhaps missing something obvious. I tried having the code below as a before\_filter, but that didn't work.

- if request.user\_agent =~ /iPhone/ - params[:format] = 'iphone' - end

Anyway, thanks for your time 🙂
