Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add CHANGELOG entry and more documentation

  • Loading branch information...
commit fe7fb931c47d4a32e64304a57318413793b3f8cb 1 parent 49c503a
@rafaelfranca authored
View
30 actionpack/CHANGELOG.md
@@ -1,5 +1,35 @@
## Rails 4.0.0 (unreleased) ##
+* Add Routing Concerns to declare common routes that can be reused inside
+ others resources and routes.
+
+ Code before:
+
+ resources :messages do
+ resources :comments
+ end
+
+ resources :posts do
+ resources :comments
+ resources :images, only: :index
+ end
+
+ Code after:
+
+ concern :commentable do
+ resources :comments
+ end
+
+ concern :image_attachable do
+ resources :images, only: :index
+ end
+
+ resources :messages, concerns: :commentable
+
+ resources :posts, concerns: [:commentable, :image_attachable]
+
+ *David Heinemeier Hansson + Rafael Mendonça França*
+
* Allow data attributes to be set as a first-level option for form_for, so you can write `form_for @record, data: { behavior: 'autosave' }` instead of `form_for @record, html: { data: { behavior: 'autosave' } }` *DHH*
* Deprecate `button_to_function` and `link_to_function` helpers.
View
8 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1591,11 +1591,15 @@ def name_for_action(as, action) #:nodoc:
# resources :comments
# end
#
+ # concern :image_attachable do
+ # resources :images, only: :index
+ # end
+ #
# These concerns are used in Resources routing:
#
- # resources :messages, concerns: :commentable
+ # resources :messages, concerns: [:commentable, :image_attachable]
#
- # or in a given scope:
+ # or in a scope or namespace:
#
# namespace :posts do
# concerns :commentable
View
6 guides/source/routing.textile
@@ -281,12 +281,18 @@ Routing Concerns allows you to declare common routes that can be reused inside o
concern :commentable do
resources :comments
end
+
+concern :image_attachable do
+ resources :images, only: :index
+end
</ruby>
These concerns can be used in resources to avoid code duplication and share behavior across routes.
<ruby>
resources :messages, concerns: :commentable
+
+resources :posts, concerns: [:commentable, :image_attachable]
</ruby>
Also you can use them in any place that you want inside the routes, for example in a scope or namespace call:
Please sign in to comment.
Something went wrong with that request. Please try again.