I`m looking to implement links that fit a certain format (seo purposes).
Here`s an example:
match '/activities-Palmdale-California', :to => 'explores#activity_by_city', :location=>'Palmdale-California'
Where the location changes for each city+state.
Is there I way to dynamically loop through an array of cities & states (predefined) in the routes file, without creating additional models etc. ?
You can have parameters in your routes, so something like the following should work:
and the
locationshould be sent to your controller action inparams[:location]. If you want to limit the urls your application will accept to just the locations in a predefined array (we’ll call itValidLocations), you can do it either in the route with the:constraintsoption:or in the controller: