Rails Route Routes: vs *

I'm starting to learn rails, and I see wildcard routes, but I saw routes listed in both of the following ways:

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

and

 /a/path/:all 

What is the difference between the two forms of the route?

+4
source share
1 answer

Have you read the Rails Guide when routing? This is a great place to start exploring routing in Rails.

For example, you will find out that your second code block is not . Instead, it corresponds to the fact that the above guide applies to the Static Segment

You will also learn that to impose restrictions on a segment, as you seem to be trying in the first block of code, you should use the parameter :constraints , for example this wildcard pattern , or as described in the guide, Routing Routing

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

However, the above restriction is redundant since the *all wildcard will match by default .* .

+13
source

All Articles