Skip to content

Commit 63041ac

Browse files
flavio-bp8
andauthored
Improves MIME type registration explanation
Co-authored-by: Petrik de Heus <[email protected]>
1 parent 5762ac1 commit 63041ac

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

guides/source/action_controller_overview.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,14 @@ class ClientsController < ApplicationController
10731073
end
10741074
```
10751075

1076-
This example works because [Rails already registers the `"application/pdf"` MIME type](https://github.com/rails/rails/blob/b26a9fd2551a2e65e8deef10f4b5ca6b99d666fb/actionpack/lib/action_dispatch/http/mime_types.rb) at startup (alongside other common types). If you need additional MIME types, call [`Mime::Type.register`](https://api.rubyonrails.org/classes/Mime/Type.html#method-c-register) in the file `config/initializers/mime_types.rb`. For example, this is how you would register the Rich Text Format (RTF):
1076+
You can call any method on `format` that is an extension registered as a MIME type by Rails.
1077+
Rails already registers common MIME types like `"text/html"` and `"application/pdf"`:
1078+
```ruby
1079+
Mime::Type.lookup_by_extension(:pdf)
1080+
# => "application/pdf"
1081+
```
1082+
1083+
If you need additional MIME types, call [`Mime::Type.register`](https://api.rubyonrails.org/classes/Mime/Type.html#method-c-register) in the file `config/initializers/mime_types.rb`. For example, this is how you would register the Rich Text Format (RTF):
10771084

10781085
```ruby
10791086
Mime::Type.register("application/rtf", :rtf)

0 commit comments

Comments
 (0)