I'm creating a new format for an iPhone/iPod connections.
My problem is that iPhones/iPods always receive the .html pages.
If I comment the format.html # index.html.erb then the devices receive
the .xml format, and If I coment this one they receive the format.iphone
wich is the expected.
In the .html pages I add some code to test if the device is really an
iPhone or not:
<% if iphone_user_agent? # Show message for iPhone users -%>
<div class="message">
<p>Using an iPhone? <a href="Foo.com the
optimised version</a>.</p>
</div>
<%else%>
<p>Welcome iPhone user!</p>
<% end -%>
And when the device is an iPhone/iPod I get the Using an iPhone? message
...
Of course I'm connecting from an iPhone/iPod or through the iPhone
simulator from Xcode.
When I use a simple browser from a computer I expect the .html versions,
wich I'm receiving as default no matter wich device/browser is
connected.
What did I miss ?
thanks,
r.
In config/initializers/mime_types.rb
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
Mime::Type.register_alias "text/html", :iphone
class ScannsController < ApplicationController
around_filter :login_required
def index
@scanns = Scann.find_by_sql("SELECT * FROM totals_diaris_avui")
@page_title="Scanns of today"
respond_to do |format|
format.iphone # action.iphone.erb
format.html # index.html.erb
format.xml { render :xml => @scanns }
end
Perhaps you could change default route to point to index.iphone when you
use your subdomain. You'd then need to ensure all your links used the
.iphone extension.
Unless there is someway to force the default format from html to
'iphone'? Wouldn't surprise me if it was possible, however, you'd need
to look it up...
I was not setting the format to iphone correctly in the application
controller, the iPhone format only was available if the user connects
from a subdomain iphone.mywebpage.com or via a custom parameter,
format=iPhone.
As I'm developing locally with the 127.0.0.1 I don't have a quick-way to
simulate iphone.127.0.0.1 or something similar, so I change the method
and simply if the user connected is from an iPhone/iPod I show their
pages directly.
I'll think in a better solution, but as this is for a test purposes, at
this moment it's ok.