I’m working on a library similar to acts_as_taggable. I’d like it to be
a
simple, one file drop-in: i.e., put my_library.rb into RAILSROOT/lib/
and
have everything work. However, the library requires a controller to
render
some stuff, so I need to be able to create the controller class, set the
routing, and extend the controller at run-time from within
my_library.rb.
I have code that creates and extends the controller properly; I’ve
tested
that it works via the console. However, the code that I have in place to
add
a route to connect a url to the extended methods in the controller
doesn’t
seem to take effect. When testing via the webrick server, I get an
unrecognized route error.
What I have in my_library.rb is something like the following:
say I’ve generated the following controller from within my_library.rb:
class ASampleController < ActionController::Base
def some_thing
render_text “hello world!”
end
end
and also from within my_library.rb I have the following code to add a
route:
ActionController::Routing::Routes.connect ‘/show/:model_name/:id’,
:controller => ‘ASampleController’, :action => :model_name.to_s
However, the route doesn’t seem to be put in place, or even recognized.
If I
examine ActionController::Routing::Routes from within the console, my
route
does not show up. When I attempt to browse to the appropriate url, I get
the
following in log/development.log:
/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:469:in
recognition_failed' /opt/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:459:in
recognize!’
/opt/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in
`dispatch
Does anyone have any suggestions as to how I could go about getting the
route recognized? Any help is greatly appreciated.