Multiple views issue in IE

4 views
Skip to first unread message

Myles Eftos

unread,
Jan 21, 2008, 10:18:36 AM1/21/08
to rails-...@googlegroups.com
Hey all,

Just found a weird issue, and I want to know if anyone else has experienced
it.

I've got multiple Mime::Type aliases:

Mime::Type.register_alias "text/html", :iphone
Mime::Type.register_alias "text/html", :mobile

And corresponding application.:format:.erb files:

application.html.erb
application.iphone.erb
application.mobile.erb

Now, it works perfectly in Firefox, but in IE, the mobile version is
rendered by default (instead of the expected html version)

After a little investigation, request.format == text/html in FF, but == */*
in IE, which is what I imagine the problem is.

If anyone else has experienced, I'll fix the bug and post it to core, but I
just want to make sure I'm not going crazy first :)

----------------------------------------------
Myles Eftos
Mobile: +61-409-293-183

MadPilot Productions
URL: http://www.madpilot.com.au
Phone: +618-9467-7651
Fax: +618-9467-6289

Try our time tracking system: 88 Miles!
http://www.88miles.net

sherod

unread,
Jan 21, 2008, 8:58:25 PM1/21/08
to Ruby on Rails Oceania
This may assist you - looks like 'Accept:' is an imprecise method of
detecting what format the client wants - the non-ie centric nature of
the rails community might be to blame for trusting it :)

http://blogs.msdn.com/ie/archive/2005/04/27/412813.aspx
http://gdsotirov.blogspot.com/2005/11/internet-explorer-and-its-accept-http.html

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

I've had funny things occur with 'Accept-Charset' and found it much
easier to not trust the browsers indication of a region and instead
let the human pick it.

Adam Salter

unread,
Jan 21, 2008, 9:48:49 PM1/21/08
to rails-...@googlegroups.com

"Accept: */*" is not invalid, but surely this should default to the
mime-type at the top of this list? whereas it seems (from Myles
example) that it is choosing the last matching example (ie :mobile).
Perhaps just putting a :html declaration at the bottom would fix it?

-Adam

Myles Eftos

unread,
Jan 21, 2008, 9:51:58 PM1/21/08
to rails-...@googlegroups.com
That is what I did in the end -

request.format = "html" if request.format == "*/*"

Fixed the problem - Looks like I'll have to dig in to the core and try to
sort out a patch...

Thanks

----------------------------------------------
Myles Eftos
Mobile: +61-409-293-183

MadPilot Productions
URL: http://www.madpilot.com.au
Phone: +618-9467-7651
Fax: +618-9467-6289

Try our time tracking system: 88 Miles!
http://www.88miles.net

Myles Eftos

unread,
Jan 21, 2008, 9:54:21 PM1/21/08
to rails-...@googlegroups.com
Oh, and it isn't picking the last one in the list (There a couple of others
in the list I omitted for brevity) - if seems to be picking one based on the
non-orderedness of Ruby Hashs.

----------------------------------------------
Myles Eftos
Mobile: +61-409-293-183

MadPilot Productions
URL: http://www.madpilot.com.au
Phone: +618-9467-7651
Fax: +618-9467-6289

Try our time tracking system: 88 Miles!
http://www.88miles.net

> -----Original Message-----
> From: rails-...@googlegroups.com
> [mailto:rails-...@googlegroups.com] On Behalf Of Adam Salter
> Sent: Tuesday, 22 January 2008 11:49
> To: rails-...@googlegroups.com
> Subject: [rails-oceania] Re: Multiple views issue in IE
>
>
>

Nathan de Vries

unread,
Jan 21, 2008, 9:56:43 PM1/21/08
to rails-...@googlegroups.com
On Tue, 2008-01-22 at 13:48 +1100, Adam Salter wrote:
> "Accept: */*" is not invalid

Yes it is. See 14.1 of RFC2616. You're confusing acceptable with
desirable.


Cheers,

--
Nathan de Vries

Nathan de Vries

unread,
Jan 21, 2008, 10:11:53 PM1/21/08
to rails-...@googlegroups.com
On Tue, 2008-01-22 at 11:54 +0900, Myles Eftos wrote:
> Oh, and it isn't picking the last one in the list...

From ActionController::AbstractRequest:

def format
@format ||= parameters[:format] ? Mime::Type.lookup_by_extension(parameters[:format]) : accepts.first
end

Where 'accepts.first' is the result of:

Mime::Type.parse(@env['HTTP_ACCEPT'])

If you want multiple HTML formats (browser, mobile, iPhone), you'll
probably want to use a 'format' query parameter or use user agent
detection (in a before_filter):

request.format = :iphone if request.env["HTTP_USER_AGENT"][/iPhone/]

Adam Salter

unread,
Jan 21, 2008, 10:33:12 PM1/21/08
to rails-...@googlegroups.com
I've gone over this several times:

If I translate 14.1 to human english:

'Accept', FOLLOWED BY colon ':', FOLLOWED BY star slash star '*/*' OR specific-type slash star 'type/*' OR specific-type slash specific-type 'type/type', OPTIONALLY FOLLOWED BY semi-colon ';', FOLLOWED BY parameters ... (plus other junk)

By my reading 'Accept: */*' fits this description.

It's a bit like XTC Vs. Adam Ant.

Myles Eftos

unread,
Jan 21, 2008, 10:37:27 PM1/21/08
to rails-...@googlegroups.com
I've got the different templates working (doing exactly as you said, but
based on subdomain). This problem isn't actually related. This problem will
show up whenever you have multiple layouts. The accepts.first is probably
what is screwing up as these are aliases, not real Mime::Types. I'll dig
through the code further when I get a chance

----------------------------------------------
Myles Eftos
Mobile: +61-409-293-183

MadPilot Productions
URL: http://www.madpilot.com.au
Phone: +618-9467-7651
Fax: +618-9467-6289

Try our time tracking system: 88 Miles!
http://www.88miles.net

> -----Original Message-----
> From: rails-...@googlegroups.com
> [mailto:rails-...@googlegroups.com] On Behalf Of Nathan de Vries
> Sent: Tuesday, 22 January 2008 12:12
> To: rails-...@googlegroups.com
> Subject: [rails-oceania] Re: Multiple views issue in IE
>

Nathan de Vries

unread,
Jan 21, 2008, 10:56:50 PM1/21/08
to rails-...@googlegroups.com
I didn't not see your double negative.

Adam Salter

unread,
Jan 22, 2008, 1:19:02 AM1/22/08
to rails-...@googlegroups.com
Ahh. I don't see what you are not saying.
Reply all
Reply to author
Forward
0 new messages