Rails: customising URL Path for map.resources

A rails patch that would help in customising the URL generated from the mapped resources.

The patch adds an option :path_replace to map.resources.

For e.g. if I want to keep my resources in English, but the URLs to talk spanish, then:

  map.resources :products, :path_replace=>'productos' do |product|
    product.resources :product_reviews, :path_replace => 'comentarios'
  end

  map.resources :tutors, :path_replace=>'tutores' do |tutor|
    product.resources :tutor_reviews, :path_replace => 'comentarios'
  end

These will yield paths like the following:

  productos/:product_id/comentarios
  tutores/:tutor_id/comentarios

The resources patch is available at rails trac.

Leave a Comment