Skip to content

Instantly share code, notes, and snippets.

@caok
Last active December 31, 2015 21:49
Show Gist options
  • Save caok/8049246 to your computer and use it in GitHub Desktop.
Save caok/8049246 to your computer and use it in GitHub Desktop.
Action Pack Variants
class ApplicationController < ActionController::Base
before_action :detect_device_variant
private
def detect_device_variant
case request.user_agent
when /iPad/i
request.variant = :tablet
when /iPhone/i
request.variant = :phone
end
end
end
class PostController < ApplicationController
def show
@post = Post.find(params[:id])
respond_to do |format|
format.json
format.html # /app/views/posts/show.html.erb
format.html.phone # /app/views/posts/show.html+phone.erb
format.html.tablet do
@show_edit_link = false
end
end
end
end
# http://coherence.io/blog/2013/12/17/whats-new-in-rails-4-1.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment