Create/unload runtime routes

Hi,

I am trying to create routes at runtime but I am finding this a but of a
challenge. I can get it to register as a route using the code below but
then when url_for( with_url_options ) is called it throws an on any
different fout error:

No route matches {:action=>“index”,
:controller=>“admin/scientific_review_processes__1__1s”

When I try to load a different meta model/controller/route I have to
stop/start the server and it will work. I want to be able to load and
unload controllers/models and routes at runtime but I have yet to make
this
work correctly.

private
    def create_route(table_name)

    #  if

Rails.application.routes.named_routes.routes[“admin_#{table_name}”.to_sym].nil?
Rails.application.routes.disable_clear_and_finalize = true

          Rails.application.routes.draw do
            namespace :admin do
              resources table_name.to_sym do as_routes end
            end
          end
          #binding.pry
          #Rails.application.routes.finalize!
      #  ActiveSupport.on_load(:action_controller)

{Rails.application.routes.finalize! }
# end
end

Does anyone know what would make such a thing work in a runtime
environment?

Thanks in advance,
Mark

On Thursday, 10 December 2015 16:48:28 UTC-5, mark wrote:

When I try to load a different meta model/controller/route I have to
stop/start the server and it will work. I want to be able to load and
unload controllers/models and routes at runtime but I have yet to make this
work correctly.

I’m missing something - why is this something that needs to happen at
runtime versus at application startup?

The code you show below can’t be the whole solution, since it’s going to
be
creating routes to controllers that either existed at application
startup
(in which case the routes could just be in routes.rb) or that are being
conjured into existence at runtime (tricky, and likely to cause exciting
thread-safety issues on some application servers).

–Matt J.