[英]Rails routing for pretty urls and get variables
Rails noob here Rails noob在这里
I have a url "/products?sports=2", which shows the products fine. 我有一个网址“/ products?sports = 2”,这表明产品很好。 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. 谢谢。
看看friendly_id宝石。
What you need is FriendlyId which is covered in this RailsCasts episode . 你需要的是这个RailsCasts剧集中涵盖的FriendlyId 。
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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.