# Using respond\_to to send multiple formats to the same view

**URL:** <https://www.ruby-forum.com/t/using-respond-to-to-send-multiple-formats-to-the-same-view/132104>\
**Category:** Rails\
**Created:** [March 17, 2008, 2:13am UTC](https://www.ruby-forum.com/t/using-respond-to-to-send-multiple-formats-to-the-same-view/132104 "2008-03-17T02:13:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlianza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ce7236/32.png) [@tlianza](https://www.ruby-forum.com/u/tlianza)\
**Post date:** [March 17, 2008, 2:13am UTC](https://www.ruby-forum.com/t/using-respond-to-to-send-multiple-formats-to-the-same-view/132104/1 "2008-03-17T02:13:59Z")

</div>

Hi All,

Hopefully it’s obvious what I’m trying to do here:

respond\_to do |format|  
format.html # show.html.erb  
format.fbml { render(:format=\>‘html’)}  
end

The problem is, the fbml version doesn’t work. Rails insists on  
looking for show.fbml.erb and won’t just render show.html.erb. I’d  
rather not have to write this view twice.

Any ideas on the syntax for this?

Thanks!  
Tom

---

<div class="post-metadata">

**Author:** ![tlianza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ce7236/32.png) [@tlianza](https://www.ruby-forum.com/u/tlianza)\
**Post date:** [March 17, 2008, 3:18am UTC](https://www.ruby-forum.com/t/using-respond-to-to-send-multiple-formats-to-the-same-view/132104/2 "2008-03-17T03:18:27Z")

</div>

On 3/16/08, Tom [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The problem is, the fbml version doesn’t work. Rails insists on  
> looking for show.fbml.erb and won’t just render show.html.erb. I’d  
> rather not have to write this view twice.

unless someone has a better idea, you can use:  
format. fbml { render :template =\> ‘my\_model\_view\_dir/show’ }

Adam

---

<div class="post-metadata">

**Author:** ![tlianza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ce7236/32.png) [@tlianza](https://www.ruby-forum.com/u/tlianza)\
**Post date:** [March 17, 2008, 3:36am UTC](https://www.ruby-forum.com/t/using-respond-to-to-send-multiple-formats-to-the-same-view/132104/3 "2008-03-17T03:36:39Z")

</div>

It was suggested in #rubyonrails this morning that you can do  
format.fbml {  
render … , :mime\_type =\> Mime::Type[“text/html”] }

On Mon, Mar 17, 2008 at 12:47 PM, Adam C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > format.html # show.html.erb
> > 
> > ```
> 
> Adam
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![tlianza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ce7236/32.png) [@tlianza](https://www.ruby-forum.com/u/tlianza)\
**Post date:** [March 17, 2008, 8:48am UTC](https://www.ruby-forum.com/t/using-respond-to-to-send-multiple-formats-to-the-same-view/132104/4 "2008-03-17T08:48:18Z")

</div>

Sorry, I should have replied in #rubyonrails this morning but it took  
me a while to figure out that solution wouldn’t work. First of all  
the Mime::Type class doesn’t support [], and second of all I’m pretty  
sure that just controls the MIME type of the response, rather than  
selecting the format of the view (I could be wrong about that though).

Adam’s suggestion (render(:template=\>…)) with the full path worked  
great. Thank you Adam!

Tom

On Mar 16, 7:35 pm, “Ryan B. (Radar)” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
