Class: BillyRouter

Inherits:
Object
  • Object
show all
Defined in:
app/models/billy_router.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/billy_router.rb', line 2

def call(env)
  # Matched from routes, you can access all matched parameters
  path = env['action_dispatch.request.path_parameters'][:path]
  slug = path.split('/').last

  page = BillyCms::Page.friendly.find(slug)
  controller_class_name = page.page_type.to_s.camelcase + 'Controller'

  begin
    controller_name = controller_class_name.constantize
  rescue NameError
    controller_name = CmsController
  end

  action_name = 'show'

  controller_name.action(action_name.to_sym).call(env)
end