Forum: Ruby on Rails copy column table before save

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
97bd2f0974055dacf53a0643b013b32e?d=identicon&s=25 Petan Cert (petan)
on 2009-02-03 14:52
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.
9b8d00f99fe595bdc45fd30439cf9c8f?d=identicon&s=25 Franz Strebel (Guest)
on 2009-02-03 14:59
(Received via mailing list)
On Tue, Feb 3, 2009 at 2:52 PM, Petan Cert
<rails-mailing-list@andreas-s.net> 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
This topic is locked and can not be replied to.