[英]Rails routing for pretty urls and get variables
Rails noob在這里
我有一個網址“/ products?sports = 2”,這表明產品很好。 但我希望網址是“/排球”
我目前有,我知道這完全是故事:
match 'volleyball' => 'products?sports=2'
有什么建議么? 謝謝。
看看friendly_id寶石。
你需要的是這個RailsCasts劇集中涵蓋的FriendlyId 。
您可能需要以下路線:
get ':sport_id', :to => 'products#show'
class ProductsController < ApplicationController
def show
render text: "sport is #{params['sport_id']}"
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.