On Wed, Aug 19, 2009 at 1:01 AM, Rails
List<[email protected]> wrote:
>> How do I render the view based on the result of the "device_type?"
>> method?
>> I am using Rails 2.3.3.
>>
>> Thank you,
>> Gleb
>
> Gleb, I am not sure, but i would think along these line
>
> def index
> format = device_type?
> respond_to do |format|
> format.html
> format.mobile_lofi { render blah}
> format.iphone { render :action => blah }
> end
> end
Close, but I think you need to set request.format, and I'd probably do
that in a before filter.
class HomeController < ApplicationController
before_filter :set_device_mime_type
def set_device_mime_type
request.format = device_type?
end
def index
respond_to do |format|
#what you said
end
end
end
I'd also strongly suggest renaming that device_type? method to
something like device_mime_type since the question mark indicates that
it should be a predicate method.
It might also be a good idea to refactor this a bit so that you only
change the format of the request if it is coming from one of the
special devices, and leave it to what the client sent otherwise.
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---