In our application, we have several pages that are available in a mobile format, but not all of them.
So, I decided to follow this tutorial: “The best way to add mobile pages” , which works well.
When a user uses a mobile device, mobile views are displayed, if available, if they will not be displayed on the desktop version.
However, I have a problem with the layout. My desktop layout and my mobile device layout are different, so when the mobile page is displayed, I would like to use my mobile phone layout and when the desktop version is displayed, I would like to use the desktop layout even if the user is on mobile device.
I added the following code to my application controller (I also added the code in this link “The best way to add mobile pages” ) to detect if the user is mobile or not, and change the layout accordingly:
layout :determine_layout
def mobile_device?
if session[:mobile_override]
session[:mobile_override] == "1"
else
(request.user_agent =~ /(iPhone|iPod|Android|webOS|Mobile)/) && (request.user_agent !~ /iPad/)
end
end
helper_method :mobile_device?
def determine_layout
if mobile_device?
"mobile"
else
"application"
end
end
However, the problem with this code is that even if the page is not available in view_mobiles, it will try to display the mobile layout, as I am checking the mobile device, not the mobile page.
? ?
view_mobiles. , .
?
,