Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/godfather/rails/routes.rb

Instance Method Summary collapse

Instance Method Details

#godfather_of(*resources) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/godfather/rails/routes.rb', line 2

def godfather_of(*resources)
  namespace = @scope[:path]
  namespace = namespace[1..-1] if namespace

  resources.each do |resource|
    Rails.application.routes.draw do
      %i(where create update destroy).each do |name|
        path = [namespace, resource, name].compact.join('/')
        controller = [namespace, resource].compact.join('/')
        to = [controller, name].join('#')
        post path => to
      end
    end
  end
end