# How to create a record in another table?

**URL:** <https://www.ruby-forum.com/t/how-to-create-a-record-in-another-table/115358>\
**Category:** Rails\
**Created:** [September 24, 2007, 12:17pm UTC](https://www.ruby-forum.com/t/how-to-create-a-record-in-another-table/115358 "2007-09-24T12:17:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CCH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/898d66/32.png) [@CCH](https://www.ruby-forum.com/u/CCH)\
**Post date:** [September 24, 2007, 12:17pm UTC](https://www.ruby-forum.com/t/how-to-create-a-record-in-another-table/115358/1 "2007-09-24T12:17:39Z")

</div>

Hi

In my Delphi GUI apps, it is common functionality  
a) to select a row  
b)then ‘append to’ ie create a row to another table with similar  
table structure

I guess the analogy would be to copy a record to another table by  
clicking an action link

How can we do it wth ActiveScaffold ?

I think the solution is to copy the record as follows :-

def self.add\_transfer\_action  
# The copy action  
define\_method(:copy) do  
new  
end

```
# Override the do_new to implement copy behavior
define_method(:do_new) do
  super
  if params["action"] == "transfer"
    model = active_scaffold_config.model
    copied_record = model.find(params[:id])

   # how do I specify the target controller ?
    model.columns.each do |column|
      @record.send("#{column.name}=",
        copied_record.send("#{column.name}")) unless column.name
        model.primary_key
    end
   #
  end
end

```

end

Q. How and where do I specify the target table in the above-mentioned  
code

---

<div class="post-metadata">

**Author:** ![CCH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/898d66/32.png) [@CCH](https://www.ruby-forum.com/u/CCH)\
**Post date:** [September 24, 2007, 2:01pm UTC](https://www.ruby-forum.com/t/how-to-create-a-record-in-another-table/115358/2 "2007-09-24T14:01:59Z")

</div>

I’m not sure how it will be different for ActiveScaffold as I don’t  
use it, but to do the actions you described in RoR, you can use  
the attributes property:

Assuming that you already have the source row called src,  
you can do

target\_row = TargetTable.new(src.attributes)
