Вопрос

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 )

Это было полезно?

Решение

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top