← Back to Upcase

Generic gem to add notes to multiple tables

(Justin Gordon) #1

I’ve got an app where for several tables, A, B, C, they could use a list of associated “Notes”.

Is there any Rails gem that provides this sort of functionality?

A notes table would have the following cols:

id, parent_id, parent_table, note, created_by_id, updated_by_id, created_at, updated_at


(Renan Gurgel) #2

I know https://github.com/ctran/annotate_models. I´m not sure if is exactly what do you want.


(Justin Gordon) #3

Not programmer notes, but notes on records. Kind of like what Devise does for auth.

Such a gem would:

  1. Create a Notes table
  2. Provide some UI hooks for displaying, it, etc.

Might be just too easy to create from scratch to make it worth a gem.


(Andy Waite) #4

Sounds like you just need a polymorphic association. It’s hard to imagine any gem that would handle this since the needs would be very app-specific.

class Note < ActiveRecord::Base
  belongs_to :noteable, polymorphic: true
class Widget < ActiveRecord::Base
  has_many :notes, as: :noteable
1 Like