mobile_fu & difference between mobile view and mobile device
If you dealt or about to consider using “mobile_fu” gem to support multiple views for the same controller action then you have to take care of this note I will mention here
Normally mobile_fu create a new format as “mobile” to differentiate mobile view from desktop view so that a url as “/topics” will have two versions “/topics” and “/topics.mobile”. The first will show the desktop version and the second will show the mobile view. This is regardless of the User-Agent which state if the source of the request is coming from desktop or mobile
I am assuming here that tablet is using the same view as desktop but you can have additional format “tablet” if you wanna have a separate view for tablets
If you called /topics directly then normally you will get either desktop view or mobile view and this will be based on your device. mobile_fu has a method “is_mobile_device?” that can be used to know if source of the call is mobile or not
So what about “mobile view” which is something different provided by mobile_fu named “is_mobile_view?” ? This is added by mobile_fu because in many web services, you might want to handle these 4 cases
Mobile Device + Mobile View
Desktop Device + Desktop View
Mobile Device + Desktop View (if you allow mobile users to see full version of the site in case you support limited set of features on mobile and user switch to desktop to use website full functionality)
Desktop Device + Mobile View (in case you wanna use the mobile view instead of the desktop view for whatever reason you have in mind. This is not a common thing websites support but can happen if someone is following a mobile url shared with him)
To have these 4 cases supported, we have to rely on two pieces of info. The first is “User Agent” which is used to know if device is mobile or not. The other piece of info can come from a cookie to store user preference. Initially a user coming from mobile will have the website served in mobile view but when user switches to desktop view, we store this preference to use move forward
When it comes to AJAX, you have to send the format in the url you are requesting so you have to call either /topics or /topics.mobile so that the server responds with the appropriate response based on whether this device is mobile or not and also based request is coming from mobile view or not. Without format, you won’t be able to do so as “in_mobile_view?” will always return false as mobile_fu logic is bypassed in case of XHR requests










