Question

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.

Was it helpful?

Solution

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

OTHER TIPS

Check out the friendly_id gem.

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top