Module: BMC::RoutesHelper

Included in:
AllHelpers
Defined in:
app/helpers/bmc/routes_helper.rb

Instance Method Summary collapse

Instance Method Details

#engine_polymorphic_path(obj, opts = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/bmc/routes_helper.rb', line 2

def engine_polymorphic_path(obj, opts = {})
  if Rails::VERSION::STRING >= "6.0.0"
    engine = obj.class.module_parents[-2]
  else
    engine = obj.class.parents[-2]
  end

  if engine.nil?
    routes = main_app
  else
    routes = engine::Engine.routes
  end

  opts = {
    controller: "/#{obj.class.to_s.tableize}",
    action: :show,
    id: obj.to_param,
    only_path: true,
  }.merge(opts)

  routes.url_for(opts)
end