Acts_as_audited - save NAME value not ID value

I have a form with many fields that can be changed. Company, Group,
Facility, Department, User, etc…

Each field has an associated table with the following fields(ID, NAME)

If a Company, Group, or Department is changed, the ‘CHANGES’ text
field of the ‘AUDITS’ table stores something like the following:

company_id:

  • 111
  • 222
    group_id:
  • 333
  • 444
    department_id:
  • 555
  • 777

This is what will show in my VIEW:
company_id - 111 - 222
group_id - 333 - 444
department_id - 555 - 777

Instead of storing the ID, I want to store the actual NAME value so I
can display something like the following in my VIEW:
company_id - ABC COMPANY - XYZ COMPANY
group_id - RED GROUP - GREEN GROUP
department_id - ACCOUNTING - PAYROLL

Anyone have any ideas on how this could be accomplished?

Thanks,

Frank

On Wed, 2010-02-03 at 12:38 -0800, Frank_in_Tennessee wrote:

  • 222
    department_id - 555 - 777

Instead of storing the ID, I want to store the actual NAME value so I
can display something like the following in my VIEW:
company_id - ABC COMPANY - XYZ COMPANY
group_id - RED GROUP - GREEN GROUP
department_id - ACCOUNTING - PAYROLL

Anyone have any ideas on how this could be accomplished?


you would have to extend the functionality of ‘acts_as_audit’ plugin.

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Frank_in_Tennessee wrote:

I have a form with many fields that can be changed. Company, Group,
Facility, Department, User, etc…

Each field has an associated table with the following fields(ID, NAME)

If a Company, Group, or Department is changed, the ‘CHANGES’ text
field of the ‘AUDITS’ table stores something like the following:

company_id:

  • 111
  • 222
    group_id:
  • 333
  • 444
    department_id:
  • 555
  • 777

This is what will show in my VIEW:
company_id - 111 - 222
group_id - 333 - 444
department_id - 555 - 777

Instead of storing the ID, I want to store the actual NAME value so I
can display something like the following in my VIEW:
company_id - ABC COMPANY - XYZ COMPANY
group_id - RED GROUP - GREEN GROUP
department_id - ACCOUNTING - PAYROLL

Anyone have any ideas on how this could be accomplished?

Don’t do that. Keep the data stored as ids in the DB, and get the names
out of the appropiate table. If you do one query for all names, there
shouldn’t be too much performance degradation.

Thanks,

Frank

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]