Rails: routes

A brief breakdown of this route:

    match “/pick_gender(/:gender)”, to: “my_controller#pick_gender”, via: “GET”, as: :pick_gender 

1. match will match a GET (i.e. it will be the same as using get) if we use via: "GET" 

You can simplify it to:

    get "/pick_gender(/:gender)", to: "my_controller#pick_gender", as: :pick_gender 

or if you want to use the => syntax to:

    get "/pick_gender(/:gender)" => "my_controller#pick_gender", as: :pick_gender 

2. to: matches this resource (the GET on the URL) to the pick_gender method of the my_controller controller 

3. finally, using as: will create a named route, i.e. you get a pick_gender_path and pick_gender_url for free as named helpers

More on named routes here:


More on Rails routes generally here:


More on match vs get` here:


Leave a Reply

Your email address will not be published. Required fields are marked *