0

Rails noob here

I have a url "/products?sports=2", which shows the products fine. But I want the url to be "/volleyball"

I currently have, which I know is completely worng:

match 'volleyball' => 'products?sports=2'

Any suggestions? Thanks.

Daniel Broughan
  • 755
  • 1
  • 9
  • 17

3 Answers3

1

Check out the friendly_id gem.

gregates
  • 6,607
  • 1
  • 31
  • 31
  • Thanks gregates..This seems to work for me actually match 'volleyball' => 'spree/products#index', :defaults => { :sports => '2' } – Daniel Broughan Sep 12 '13 at 15:40
1

What you need is FriendlyId which is covered in this RailsCasts episode.

Francisco Canela
  • 1,084
  • 1
  • 7
  • 14
  • Also, [this tutorial](https://gist.github.com/jcasimir/1209730) covers many configurations which you could find useful. I had to place it in reply because I can not post more than 2 links per reply. – Francisco Canela Sep 12 '13 at 15:41
0

You may want the following route:

get ':sport_id', :to => 'products#show'

class ProductsController < ApplicationController
  def show
    render text: "sport is #{params['sport_id']}"
  end
end
Marlin Pierce
  • 9,931
  • 4
  • 30
  • 52