Skip to content

Instantly share code, notes, and snippets.

@rbmrclo
Last active March 29, 2018 14:34
Show Gist options
  • Save rbmrclo/8313014 to your computer and use it in GitHub Desktop.
Save rbmrclo/8313014 to your computer and use it in GitHub Desktop.
Rails Best Practices: Routing Concerns in Rails 4
# 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