# Params

**URL:** <https://www.ruby-forum.com/t/params/83237>\
**Category:** Rails\
**Created:** [January 24, 2007, 4:15pm UTC](https://www.ruby-forum.com/t/params/83237 "2007-01-24T16:15:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chika](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@Chika](https://www.ruby-forum.com/u/Chika)\
**Post date:** [January 24, 2007, 4:15pm UTC](https://www.ruby-forum.com/t/params/83237/1 "2007-01-24T16:15:33Z")

</div>

Hi, I’m building a database and I need to save all the changes users do.  
This means that every time something goes to the method update, create  
or destroy I have to save some information in another table. That’s  
fine, the problem is that I need to store all the new information in one  
field, and the old information in another.  
I tried to do so doing the following:

ModificacionesEmpresa.create(:empresa\_id =\>@empresa.id, :usuario\_id =\>  
session[:user\_id],:tipo =\> ‘U’, :tupla\_nuevo =\> params[:empresa].to\_s,  
:tupla\_antiguo =\> @tupla)

The problem is that neither params[:empresa].to\_s nor :tupla\_antiguo =\>  
@tupla  
are save as readable information… I think I might need to do some  
kind of method to get everything in one big string… while I do thata,  
Anybody have a smarter solution?

---

<div class="post-metadata">

**Author:** ![Chika](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@Chika](https://www.ruby-forum.com/u/Chika)\
**Post date:** [January 24, 2007, 5:19pm UTC](https://www.ruby-forum.com/t/params/83237/2 "2007-01-24T17:19:12Z")

</div>

Chika wrote:

> The problem is that neither params[:empresa].to\_s nor :tupla\_antiguo =\>  
> @tupla  
> are save as readable information… I think I might need to do some  
> kind of method to get everything in one big string… while I do thata,  
> Anybody have a smarter solution?

You can turn an object into a big string (in Rails) by using the to\_yaml  
method. In my app this looks like this:

> > p = Post.new :permalink=\>“[http://permalink.com](http://permalink.com)”, :title=\>“post title”  
> > =\> #\<Post:0xb72619a4 @new\_record=true,  
> > @attributes={“permalink”=\>“[http://permalink.com](http://permalink.com)”, “title”=\>“post title”,  
> > “blog\_id”=\>nil, “content”=\>nil, “published\_at”=\>nil, “created\_at”=\>nil}\>

> > str = p.to\_yaml  
> > =\> “— !ruby/object:Post \nattributes: \n permalink:  
> > [http://permalink.com](http://permalink.com)\n title: post title\n blog\_id: \n content: \n  
> > published\_at: \n created\_at: \nnew\_record: true\n”

Then when you need it load it up again use:

> > YAML::load(str)  
> > =\> #\<Post:0xb7258aac @new\_record=true,  
> > @attributes={“permalink”=\>“[http://permalink.com](http://permalink.com)”, “title”=\>“post title”,  
> > “blog\_id”=\>nil, “content”=\>nil, “published\_at”=\>nil, “created\_at”=\>nil}\>

Alternatively, instead of using a big string, you might want to consider  
using Rick O.'s acts\_as\_versioned plugin:

> **[Acts As Versioned Plugin](http://juixe.com/techknow/index.php/2006/07/05/acts-as-versioned-plugin/)**
>
> The acts as versioned plugin allows you to manage different versions of a model record so that you can revert to a previous version or create new ones. To install execute the following command: scr…

---

<div class="post-metadata">

**Author:** ![Chika](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@Chika](https://www.ruby-forum.com/u/Chika)\
**Post date:** [January 24, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/params/83237/3 "2007-01-24T17:31:43Z")

</div>

On Wed, 2007-01-24 at 16:15 +0100, Chika wrote:

> The problem is that neither params[:empresa].to\_s nor :tupla\_antiguo =\>  
> @tupla  
> are save as readable information… I think I might need to do some  
> kind of method to get everything in one big string… while I do thata,  
> Anybody have a smarter solution?

* * *

I think you have to ‘flatten’ a hash to a string.

check out ‘acts\_as\_audited’ which probably does what you want to do or  
will show you the code they use which might give you inspiration.

> **[acts\_as\_audited](https://opensoul.org/2006/07/21/acts_as_audited/)**
>
> NOTE: This article is out of date. Visit the project on Github or the mailing list for up-to-date information.

Craig

---

<div class="post-metadata">

**Author:** ![Chika](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@Chika](https://www.ruby-forum.com/u/Chika)\
**Post date:** [January 25, 2007, 7:43pm UTC](https://www.ruby-forum.com/t/params/83237/4 "2007-01-25T19:43:42Z")

</div>

Craig W. wrote:

> check out ‘acts\_as\_audited’ which probably does what you want to do or  
> will show you the code they use which might give you inspiration.
> 
> [acts\_as\_audited - Brandon Keepers](http://opensoul.org/2006/07/21/acts_as_audited/)

Great I did it.  
Maybe you know more about act\_as\_audited and can help me with this.

I have a table “people” that is related wuith the table “area” through  
the table “peoplearea”, meaning that each person may have many areas.  
The “peoplearea” and the “people” models are being audited, and it  
works. The problem is that if I’m editing a person info, and I add or  
delete a new area, the “audits” table show this changes as destroying or  
creating the table “peoplearea” and I need to be saved as a change made  
over the person. Is this possible with this plugin?  
Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Chika](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@Chika](https://www.ruby-forum.com/u/Chika)\
**Post date:** [January 24, 2007, 5:32pm UTC](https://www.ruby-forum.com/t/params/83237/5 "2007-01-24T17:32:48Z")

</div>

Chika wrote:

> Hi, I’m building a database and I need to save all the changes users do.  
> This means that every time something goes to the method update, create  
> or destroy I have to save some information in another table.

You can also use ActiveRecord::Observer for this. See docs

Regards

Massimo  
[http://www.addsw.it](http://www.addsw.it)
