Creating SEO friendly URLs in Rails 3

三世轮回 提交于 2019-12-03 04:44:32
match '/:category_slug/:country_slug', :to => 'things#index'

Then you'll need to update your action to look up everything using params[:category_slug] and params[:country_slug] instead of the ids. Look at the slugged gem to generate slugs.

In your category model add the method

def to_param
   "#{category_name.parameterize}/#{location_name.parameterize}"
end

where category_name and location_name are where you input where you have have the names stored.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!