customize rails url with username

前端 未结 4 1319
日久生厌
日久生厌 2020-12-08 12:42

I want to copy the twitter profile page and have a url with a username \"http://www.my-app.com/username\" and while I can manually type this into the address bar and navigat

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 12:53

    I know this questions is old but it will help someone.

    You could try the below. I've used it in a rails 4 project and all seems to be working great. The reason for the as: :admin is I also had a resources posts outside of this scope. It will add a admin to the helper calls e.g. admin_posts_path

    scope ":username", module: 'admin', as: :admin do
      get '', to: 'profiles#show'
      resources :posts
    end
    

提交回复
热议问题