# Copy column table before save

**URL:** <https://www.ruby-forum.com/t/copy-column-table-before-save/159327>\
**Category:** Rails\
**Created:** [February 3, 2009, 2:52pm UTC](https://www.ruby-forum.com/t/copy-column-table-before-save/159327 "2009-02-03T14:52:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![petan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@petan](https://www.ruby-forum.com/u/petan)\
**Post date:** [February 3, 2009, 2:52pm UTC](https://www.ruby-forum.com/t/copy-column-table-before-save/159327/1 "2009-02-03T14:52:54Z")

</div>

Hi,

I would like to copy one column to another before it’s saved.

For example:  
\<% form … %\>  
\<%= %\>f.text-field: about %\>  
\<%= f.text-field: price %\>  
\<% end %\>

Could I copy price to another table column before it is saved?  
THank you.

---

<div class="post-metadata">

**Author:** ![petan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@petan](https://www.ruby-forum.com/u/petan)\
**Post date:** [February 3, 2009, 2:59pm UTC](https://www.ruby-forum.com/t/copy-column-table-before-save/159327/2 "2009-02-03T14:59:23Z")

</div>

On Tue, Feb 3, 2009 at 2:52 PM, Petan C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Could I copy price to another table column before it is saved?  
> THank you.

You can do this by using the before\_save call back.

In your model, just define a method called before\_save

def before\_save  
other\_column = price  
end
