Last active
March 29, 2018 14:34
-
-
Save rbmrclo/8313014 to your computer and use it in GitHub Desktop.
Rails Best Practices: Routing Concerns in Rails 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Routing Concerns is an attempt to DRY up your config/routes.rb. | |
# The basic idea is to define common sub-resources (like comments) | |
# as concerns and include them in other resources/routes. | |
# Here’s the obvious example: | |
concern :commentable do | |
resources :comments | |
end | |
concern :remarkable do | |
resources :remarks | |
end | |
resources :posts, :concerns => :commentable | |
resources :articles, :concerns => [:commentable, :remarkable] # can include several | |
# The above is equivalent to the following Rails 3 code: | |
resources :posts do | |
resources :comments | |
end | |
resources :articles do | |
resources :comments | |
resources :remarks | |
end | |
# source: http://net.tutsplus.com/tutorials/ruby/digging-into-rails-4/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment