Consider this setup:
class CommentsController < ApplicationController
def index
@comments = Comment.find(:all)
respond_to do |format|
format.html
format.iphone { render :content_type => Mime::HTML }
end
end
end
If app/views/layouts/comments.html.erb exists, then it's assumed that it'll work for both formats by the layout picking algorithm. But of course it won't, so when you hit the iphone format, you'll get an error from assert_existence_of_template_file(layout).
The problem is that the default_layout is set at inheritance time (by inherited_with_layout) to be format indifferent.Thus, if any layout exists for this action, regardless of the format, it's assumed that all formats for this action will be able to use that layout. Which is not the case.
So we need to change the way default_layout is set and handled to consider the layout. Examine the format of the layout template and only assign the default layout to formats that match that.