I’ve got same routes inside namespace and subdomain constraint.
First is used on production, second in development. How can remove this duplication?
constraints :subdomain => 'api' do
scope :module => "api" do
resources :users
resources :orders
end
end
namespace :api do
resources :users
resources :orders
end
Well,
do ... endcreates a block. If you have a block that’s repeated you can instead save it to a variable by turning it into a Proc, by passing it toProc.neworproc(the latter is just a shortcut for the former):Then you can pass the Proc (
res) as a block argument to any method that expects a block by prepending it with&:Here’s a great article on using blocks, Procs, and lambdas in Ruby.