Module: IsItIPhone
- Defined in:
- lib/is_it_iphone.rb
Overview
Module to be included in your ApplicationController class See README.txt for description of how to use this
Instance Method Summary collapse
-
#adjust_format_for_iphone ⇒ Object
Call this as a before_filter if you want to display the iPhone view (i.e., index.iphone.erb) if one exists.
-
#iphone_request? ⇒ Boolean
Returns true if the request or format parameter came from an iPhone.
-
#iphone_user_agent? ⇒ Boolean
Returns true if the request USER AGENT came from an iPhone (specfications from developer.apple.com).
Instance Method Details
#adjust_format_for_iphone ⇒ Object
Call this as a before_filter if you want to display the iPhone view (i.e., index.iphone.erb) if one exists. Note: According to Apple iPhone Web Developer guidelines, websites should show the normal page and then give the user the option to see it formatted for their iPhone.
20 21 22 23 24 25 |
# File 'lib/is_it_iphone.rb', line 20 def adjust_format_for_iphone if iphone_request? && File.exists?(File.join(RAILS_ROOT, 'app', 'views', self.controller_name, "#{self.action_name}.iphone.erb")) request.format = :iphone end end |
#iphone_request? ⇒ Boolean
Returns true if the request or format parameter came from an iPhone
11 12 13 |
# File 'lib/is_it_iphone.rb', line 11 def iphone_request? params[:format] ? params[:format] == 'iphone' : iphone_user_agent? end |
#iphone_user_agent? ⇒ Boolean
Returns true if the request USER AGENT came from an iPhone (specfications from developer.apple.com)
6 7 8 |
# File 'lib/is_it_iphone.rb', line 6 def iphone_user_agent? !!(request.env['HTTP_USER_AGENT'] && request.env['HTTP_USER_AGENT'][/(Mobile\/.+Safari)/]) end |