Search code examples
ruby-on-railsactiverecordhistory

track history of active record changes and its association


I want to track the history the active record and association. I have a many to many association:

class BookList
  has_many :book_list_items
  has_many :books, through: :book_list_items
end

class BookListItem
  belongs_to :book
  belongs_to :book_list

  attr_accessable :position
end

class Book
  has_many :book_list_items
  has_many :book_lists, through: :book_list_items
end

how do I track the history of BookList like this:

  • add book to a book list
  • remove book from a book list
  • update position of a book in a book list

how do I implement this structure


Solution

  • http://railscasts.com/episodes/255-undo-with-paper-trail

    This is a great rails cast that will work great for you based on the information you provided