aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorBrandon Weaver <baweaver@users.noreply.github.com>2016-12-14 17:17:44 -0800
committerGitHub <noreply@github.com>2016-12-14 17:17:44 -0800
commit6a116bd9091fc68dc26317b398ebcbdfe8c34155 (patch)
tree5abd42d0d0201f279faf01592eb57389231ffc2f /guides
parent1f0fe334f577479ad524cb990bef4454585857c0 (diff)
downloadrails-6a116bd9091fc68dc26317b398ebcbdfe8c34155.tar.gz
rails-6a116bd9091fc68dc26317b398ebcbdfe8c34155.tar.bz2
rails-6a116bd9091fc68dc26317b398ebcbdfe8c34155.zip
Add note on defaults block option
When I was looking for how to default the entire routes file to JSON I could only find the postfix option. It was mentioned on IRC that you could do this with a block as well and I had not found it in the documentation.
Diffstat (limited to 'guides')
-rw-r--r--guides/source/routing.md8
1 files changed, 8 insertions, 0 deletions
diff --git a/guides/source/routing.md b/guides/source/routing.md
index 937e313663..86492a9332 100644
--- a/guides/source/routing.md
+++ b/guides/source/routing.md
@@ -603,6 +603,14 @@ get 'photos/:id', to: 'photos#show', defaults: { format: 'jpg' }
Rails would match `photos/12` to the `show` action of `PhotosController`, and set `params[:format]` to `"jpg"`.
+You can also use `defaults` in a block format to define the defaults for multiple items:
+
+```ruby
+defaults format: :json do
+ resources :photos
+end
+```
+
NOTE: You cannot override defaults via query parameters - this is for security reasons. The only defaults that can be overridden are dynamic segments via substitution in the URL path.
### Naming Routes