Skip to content

Instantly share code, notes, and snippets.

@pierre-pretorius
Last active August 29, 2015 14:17
Show Gist options
  • Save pierre-pretorius/237a1d50fad4a0bac82e to your computer and use it in GitHub Desktop.
Save pierre-pretorius/237a1d50fad4a0bac82e to your computer and use it in GitHub Desktop.
Rails: Workaround to place variant in URL
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