Rod McLaughlin

How to use 'routesfordummies' (10 oct 12)

Create a new Rails project

In the Gemfile, add

gem 'routesfordummies', github: 'pdxrod/routesfordummies'

Then create a file in config/initializers which contains

require 'routesfordummies'
include Routesfordummies
insertabcdroutes(:app => 'Myapp', :controller => 'posts', :action => 'act')

where 'Myapp' is your app, 'posts' is the first part of a controller name, eg. 'posts', not 'posts_controller', and 'act' is the name of a public method in that controller. At the top of the controller, add

require 'routesfordummies'
include Routesfordummies

and inside the public method 'act' in the posts controller, use method 

url2array( params ) 

to get the url as an array (eg. posts/x/y/z becomes ['x', 'y', 'z']), and method

params2hash( params ) 

to get the parameters as a hash (eg. url?x=y becomes {'x' => 'y'})

I explain why you might want to use this gem on 


Portland London