Skip to content

Commit 81ad04c

Browse files
authored
Merge pull request rails#52597 from flavio-b/patch-1
Explains that `application/pdf` is already registered by Rails [ci skip]
2 parents dcd4e10 + 63041ac commit 81ad04c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

guides/source/action_controller_overview.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,10 +1073,17 @@ class ClientsController < ApplicationController
10731073
end
10741074
```
10751075

1076-
For this example to work, you have to add the PDF MIME type to Rails. This can be done by adding the following line to the file `config/initializers/mime_types.rb`:
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
1079-
Mime::Type.register "application/pdf", :pdf
1086+
Mime::Type.register("application/rtf", :rtf)
10801087
```
10811088

10821089
NOTE: Configuration files are not reloaded on each request, so you have to restart the server for their changes to take effect.

0 commit comments

Comments
 (0)