Last active
August 29, 2015 14:17
-
-
Save pierre-pretorius/237a1d50fad4a0bac82e to your computer and use it in GitHub Desktop.
Rails: Workaround to place variant in URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_filter :set_variant | |
def set_variant | |
if request.format == :mobile | |
if request.xhr? | |
request.format = :js | |
else | |
request.format = :html | |
end | |
request.variant = :mobile | |
end | |
end | |
def url_options | |
defaults = {} | |
defaults[:format] = request.path_parameters[:format] if request.variant.try(:include?, :mobile) | |
super.merge(defaults) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment