Ruby on Rails Friday, December 11, 2015



On Thursday, 10 December 2015 16:48:28 UTC-5, mark wrote:
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.


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 Jones

 
    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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/879f03ff-982e-44ea-8e9c-095a7764aab6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment