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
- September 2011
- April 2011
- March 2011
- December 2010
- November 2010
- September 2010
- August 2010
- July 2010
- June 2010
- April 2010
- March 2010
- November 2009
- October 2009
- September 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- November 2008
- October 2008
- September 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- January 2008
- April 2007
- March 2007
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!

