customize rails url with username

前端 未结 4 1360
日久生厌
日久生厌 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:55

    To create urls you need to define to_param method for your user model (read here).

    class User < ActiveRecord::Base
      def to_param 
        username
      end
    end
    

提交回复
热议问题