문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top