resource_controller
resource_controller copied to clipboard
R_C and MimeType::register_alias aliased mime types?
Hello, I have an application that serves two different template sets depending on the URL it is called with. For this purpose I have (in config/initializers/mime_types.rb)
Mime::Type.register_alias "text/html", :iframe
and (in application_controller.rb)
before_filter :adjust_format
def adjust_format
request.format = :iframe if request.subdomains.first == "iframe" and request.format == :html
end
This works fine
- with non-R_C controllers and no explicit "respond_to" block,
- with R_C controllers and no explicit "wants.html" block,
- with R_C controllers and a duplicated "wants.html" block as "wants.iframe".
But this is hardly DRY. How can I make R_C recognize the registered MIME type aliases, so that (in my case) it sees that the :iframe format is just an alias for :html, and uses the "wants.html" block but renders the :iframe template if "request.format==:iframe"?
Thank you!
Update: it seems that just doubling the wants.html blocks as "wants.iframe" is not enough - then I get "TemplateMissing" exceptions, even when all templates are there.