Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails routing with a parameter that includes slash(/)

Tags:

I would like to set the routings as follows

  • /url/http://google.com to urls controller and index action.

What I have now in routes.rb is:

match "urls/:url" => "urls#index" 

The routing doesn't seem to work because the slashed in :url.

like image 698
TK. Avatar asked Nov 25 '10 02:11

TK.


People also ask

What are nested routes in Rails?

In a nested route, the belongs_to (child) association is always nested under the has_many (parent) association. The first step is to add the nested routes like so: In the above Rails router example, the 'index' and 'show' routes are the only nested routes listed (additional or other resources can be added).

How many types of routes are there in Rails?

Rails RESTful Design which creates seven routes all mapping to the user controller. Rails also allows you to define multiple resources in one line.

What is match in Rails routes?

Rails routes are matched in the order they are specified, so if you have a resources :photos above a get 'photos/poll' the show action's route for the resources line will be matched before the get line. To fix this, move the get line above the resources line so that it is matched first.


1 Answers

Or you can use Route Globbing:

match "urls/*url" => "urls#index" 

You can access the values in your controller via params[:url]

Reference: http://guides.rubyonrails.org/routing.html Search for "Route Globbing"

like image 114
Imran Avatar answered Sep 20 '22 19:09

Imran