Rails wildcard routes : vs *

19,617

Have you read the Rails Guide on routing yet? That is a great place to start learning about routing in Rails.

For instance, you will learn that your 2nd code block is not a wildcard route. Instead it matches what the guide above refers to as a Static Segment

You'll also learn that to impose restrictions on a segment as you appear to be attempting in the first code block, you must use the :constraints option, such as this wildcard route, or as the guide above refers to them, Route Globbing

GET  "/a/path/*all", :constraints => { :all => /.*/ }

However, the above constraint is redundant since the wildcard *all is going to match .* by default anyway.

Share:
19,617
Jeff Storey
Author by

Jeff Storey

Updated on June 15, 2022

Comments

  • Jeff Storey
    Jeff Storey almost 2 years

    I'm starting to learn rails, and I'm seeing the terminology wildcard routes, but I've seen routes listed both of the following ways:

    /a/path/*all', :all => /.*/
    

    and

    /a/path/:all
    

    What is the difference between these two route forms?