friendly_id on profile using a param from user model?
-
13-11-2019 - |
Pergunta
Im following the casts http://railscasts.com/episodes/314-pretty-urls-with-friendlyid?autoplay=true on friendly_id
Having a user model with field "login" And a profile model with a "user_id" that belongs to user
How could I setup friendly_id so that it uses the login field from User model for its slug and get /profiles/1 to /profiles/username ( = login from User model )
Solução
Friendly_id will use the column or method name you provide in friendly_id configuration. So, you can do this:
class Profile
belongs_to :user
friendly_id :profile_permalink, use: :slugged
protected
def profile_permalink
user.login
end
end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow