I am using JQuery Mobile for my mobile site, and am switching between that and my normal full PC site via a mobile_device? method from Railscast#199
application_controller.rb
before_filter :prepare_for_mobile
def mobile_device?
if session[:mobile_param]
session[:mobile_param] == "1"
else
request.user_agent =~ /Mobile/
end
end
helper_method :mobile_device?
def prepare_for_mobile
session[:mobile_param] = params[:mobile] if params[:mobile]
if mobile_device?
if request.format == :js
request.format = :mobilejs
else
request.format = :mobile
end
end
end
This method allows me to switch from my JQuery mobile site to my PC site.
<%= link_to "PC Site", :mobile => 0 %>
However, it does not load the PC-site stylesheet. Therefore, the page has to be reloaded a second time for the CSS to take affect.
How can I load the CSS on the first try?
EDIT:
My stylesheets are added separately to application.html.erb and application.mobile.erb
application.html.erb
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
application.mobile.erb
<%= stylesheet_link_tag "mobile" %>
<%= javascript_include_tag "mobile" %> # this is where my jquery mobile js file is
The issue was that jquery Mobile defaults to AJAX, so all I needed to do was to disable it as follows.