rails/rails — pull request #10525 by chingor13 (2013-05-08 21:44:00+00:00)
Title: LookupContext js/html fallback is hacked in there

`ActionView::LookupContext` is hardcoded to append the :html format whenever :js is set as the format. A user may want to extend this behavior to their own custom defined formats (for example a :mobile format could fallback to :html as well).

This current behavior is the magic behind allowing you to render an html partial within a javascript response.

```ruby
# in new.js.erb
# will render the _form.html.erb partial
render partial: 'form', locals: {object: @object}
```

This change allows you to specify your own fallbacks easily. In somewhere like `config/initializers/mime_types.rb`:
```ruby
MimeTypes.register_alias "text/html", :mobile
ActionView::LookupContext.format_fallbacks[:mobile] = [:html]
```
Now, if you have a request where the format is :mobile, it will try to render a mobile template first, and fallback to the html template. Additionally, you could render an html partial within a mobile template.

This behavior is already being tested in `actionpack/test/template/lookup_context_test.rb`.