# Acts\_as\_audited - save NAME value not ID value

**URL:** <https://www.ruby-forum.com/t/acts-as-audited-save-name-value-not-id-value/182855>\
**Category:** Rails\
**Created:** [February 3, 2010, 9:40pm UTC](https://www.ruby-forum.com/t/acts-as-audited-save-name-value-not-id-value/182855 "2010-02-03T21:40:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_in\_Tennessee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/dec6dc/32.png) [@Frank\_in\_Tennessee](https://www.ruby-forum.com/u/Frank_in_Tennessee)\
**Post date:** [February 3, 2010, 9:40pm UTC](https://www.ruby-forum.com/t/acts-as-audited-save-name-value-not-id-value/182855/1 "2010-02-03T21:40:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Frank\_in\_Tennessee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/dec6dc/32.png) [@Frank\_in\_Tennessee](https://www.ruby-forum.com/u/Frank_in_Tennessee)\
**Post date:** [February 4, 2010, 6:53pm UTC](https://www.ruby-forum.com/t/acts-as-audited-save-name-value-not-id-value/182855/2 "2010-02-04T18:53:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Frank\_in\_Tennessee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/dec6dc/32.png) [@Frank\_in\_Tennessee](https://www.ruby-forum.com/u/Frank_in_Tennessee)\
**Post date:** [February 5, 2010, 3:36am UTC](https://www.ruby-forum.com/t/acts-as-audited-save-name-value-not-id-value/182855/3 "2010-02-05T03:36:00Z")

</div>

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](http://www.marnen.org)  
removed\_email\_address@domain.invalid
