ID + Slug name in URL in Rails (like in StackOverflow)

前端 未结 6 2008
逝去的感伤
逝去的感伤 2020-12-28 08:29

I\'m trying to achieve URLs like this in Rails:

http://localhost/posts/1234/post-slug-name

with both ID and slug name instead of either

6条回答
  •  忘掉有多难
    2020-12-28 09:15

    You'll want to add a regular route with Route Globbing in addition to your resource route (assuming of course that's how your posts routes are defined). For example,

    map.resources :posts
    map.connect '/posts/:id/*slugs', :controller => 'posts', :action => 'show'
    

提交回复
热议问题