norman / friendly_id

FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It allows you to create pretty URL’s and work with human-friendly strings as if they were numeric ids for ActiveRecord models.
http://norman.github.io/friendly_id/
MIT License
6.15k stars 591 forks source link

Access the slug history for a record #946

Closed oyeanuj closed 4 years ago

oyeanuj commented 4 years ago

Hey @parndt, quick question, and apologies if this is already somewhere in the docs and I might have missed. I'm using the history module with the library. I'm wondering if there is a way to get all the previous slug history for a record?

thank you!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

parndt commented 4 years ago

@oyeanuj I haven't ever used this module, but it looks like you might be able to use a method like slug_table_record but without the .first at the end.

This could probably helpfully be refactored to something like this:

def slug_table_record(id)
  slug_table_records(id).first
end

def slug_table_records(id)
  select(quoted_table_name + '.*')
    .joins(:slugs)
    .where(slug_history_clause(id))
    .order(Slug.arel_table[:id].desc)
end
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.