Forum: Ruby on Rails Best way to force a respond_to format

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
dusty (Guest)
on 2007-01-20 06:57
(Received via mailing list)
I am playing around with the idea of adding to the HTTP_ACCEPT header
method and trying to utilize WURFL for detecting mobile devices by
USER_AGENT instead.  I'm thinking I will set up some kind of
before_filter in my controller, to intercept all requests and compare
the USER_AGENT to some data source.

If I detect that the USER_AGENT is a mobile device, then I'd like to
force a particular mime-type and format.  If I can't find it, then I
may just fall through to the typical ACCEPT header.

I'm wondering what others thoughts are on the best way to do this.

I have found that I can simply set the params[:format] to what I want.

such as:

before_filter :typecheck
def typecheck
  somelogic...
  params[:format] = "xhtmlmp"
  or...
  params[:format] = "wml"
end


Then in my view, I will have a respond_to block something like.

respond_to do |format|
  format.html
  format.xml { :render :xml => @object.to_xml }
  format.xhtmlmp { render :template => 'object/xhtmlmp-index',
                                      :layout => 'xhtmlmp' }
  format.wml { render :template => 'object/wml-index',
                                :layout => 'wml' }
end

I see I could also just set the request.env["HTTP_ACCEPT"] parameter to
the appropriate mime-type that will give me the correct format as well.

Anyone have any suggestions?  Do you think this idea makes any sense?

Thanks for any tips or hints.
This topic is locked and can not be replied to.