respond_to - same content, different mime type

I have some basic respond_to blocks that essentially look like this:

    respond_to do |format|       format.iphone { render }       format.mobile { render }     end

This is working great right now and I have it all over the place in my code. Kind of odd that there's no format for just plain ol' HTML right? Right. Since I'm not building a desktop browser version yet, I'm not terribly concerned about supporting desktop browsers, but I do want something that at least works. But here's the problem:

- the iphone version doesn't work on all desktop browsers and won't for the foreseeable future (yeah, so i went a little iphone crazy) - the mobile version's MIME type is "application/vnd.wap.xhtml+xml" which won't work on desktop browsers

For now what I'd like to do is render the mobile version to desktop browsers but with a mime type of "text/html". Question is, what is the easiest way to accomplish this given a fair amount of existing respond to blocks and templates named with *.mobile.erb

I'm tempted to just take the easy way out and change the mime type of mobile to "text/html", but am curious if there are any smarter alternatives.

Um. format.html? Rails assumes that format if there isn't a different one explicitly requested.

Peace, Phillip

Good to know. But if I'm going to render the same template as another format, some changes will need to be made. But maybe it's as simple as changing all templates named "*.mobile.erb" to "*.erb" so that format.html can find them. Or if that doesn't work use a variation on the render call to force the html format to render the mobile template.

or use partials.

Phillip

or use partials.

Phillip

Good idea. I ended up actually not using partials (since it would involve moving a bunch of files around). But this combo of methods seems to work:

    respond_to do |format|       format.iphone { }       format.mobile { }       format.html { render :action => "theaction.mobile.erb" }     end

This almost just works, but rails doesn't know how to find the mobile layout. So I did this:

layout :force_to_mobile_layout

    def force_to_mobile_layout       if @iphone # only trick part: since :iphone format is just an alias for text/html, we have to do our own check         "application.iphone.erb"       else         "application.mobile.erb"       end     end