Class: ActionDispatch::Routing::Mapper

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

Instance Method Summary collapse

Instance Method Details

#databound(*resources) ⇒ Object



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

def databound(*resources)
  namespace = @scope[:path]
  namespace = namespace[1..-1] if namespace
  opts = resources.pop if resources.last.is_a?(Hash)

  resources.each do |resource|
    Rails.application.routes.draw do
      controller_name = [namespace, resource].compact.join('/')
      Databound::Controller.find_or_create(controller_name, resource, opts)

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