Adding Custom Routes for Radiant Projects
0
While integrating simple_captcha into the guestbook extension of Radiant, I had to add a special route for the simple_captcha to work properly.
Unfortunately, the routes file of a radiant project does nothing but to load the routes file from radiant gem itself:
load File.join(RADIANT_ROOT, "config", "routes.rb")
Calling ActionController::Routing::Routes.draw again will clear all the routes that have been defined in the gem routes file, so you have to either modify the code of the gem, or copy the code from routes.rb of the gem radiant to the projects route file.
Or you can append your new routes using add_named_route instead of draw. Since the simple captcha route is supposed to be defined before radiant routes, you can manipulate the routes array as in the last line of the following sample:
load File.join(RADIANT_ROOT, "config", "routes.rb")
ActionController::Routing::Routes.add_named_route(
'simple_captcha',
'/simple_captcha/:action',
:controller => 'simple_captcha')
ActionController::Routing::Routes.routes.unshift(
ActionController::Routing::Routes.routes.pop)
add_route is another method similar to add_named_route, but it doesn't require a name parameter; it can also be used. Note that both aren't documented well in the rails api documentation.
The Previous add_named_route call is equivalent to map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha' at the end of the routing block that is passed to draw.
add_route('/path', {options}) is equivalent to map.connect '/path' , {options}.
They can sometimes be very useful .
Witten By:
Mahmoud Said (blog.modsaid.com)
Post a Comment
eSpace podcast Prodcast
Archive
Latest Comments
- SpectraMind Commented on Egypt Wins UK's National Outsourcing Association Award
- Rofaida Awad Commented on Go Egypt Go!
- Different Mike Commented on Only idiots change their iPhone root password!
- Mike Commented on Only idiots change their iPhone root password!
- smile Commented on Only idiots change their iPhone root password!

