# Using Insert statement in active record?

**URL:** <https://www.ruby-forum.com/t/using-insert-statement-in-active-record/143521>\
**Category:** Ruby\
**Created:** [July 19, 2008, 11:01pm UTC](https://www.ruby-forum.com/t/using-insert-statement-in-active-record/143521 "2008-07-19T23:01:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anukulsinghal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@anukulsinghal](https://www.ruby-forum.com/u/anukulsinghal)\
**Post date:** [July 19, 2008, 11:01pm UTC](https://www.ruby-forum.com/t/using-insert-statement-in-active-record/143521/1 "2008-07-19T23:01:02Z")

</div>

Hi,

I know this would be a simple solution to provide for any one of you. I  
am new to active record and this is what I have currently done:

require ‘rubygems’  
require ‘active\_record’

puts “connecting to db…”

ActiveRecord::Base.establish\_connection(  
:adapter =\> “mysql”,  
:host =\> “localhost”,

# :username =\> “myuser”,

```
:password => "schumi58",
:database => "test"

```

)

puts “connection established”

ActiveRecord::Schema.define do

drop\_table(:testTable)

create\_table(:testTable) do |t|  
t.column :name, :string  
end  
end

I am also referring to Active Record’s rdoc but am not able to make out  
how to use the insert statement in the above code. Can anyone help me in  
using INSERT statement in my code above?

Thanks,  
Anukul

---

<div class="post-metadata">

**Author:** ![anukulsinghal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@anukulsinghal](https://www.ruby-forum.com/u/anukulsinghal)\
**Post date:** [July 20, 2008, 2:15am UTC](https://www.ruby-forum.com/t/using-insert-statement-in-active-record/143521/2 "2008-07-20T02:15:05Z")

</div>

Anukul S. wrote:

> I am also referring to Active Record’s rdoc but am not able to make out  
> how to use the insert statement in the above code. Can anyone help me in  
> using INSERT statement in my code above?
> 
> Thanks,  
> Anukul

Maybe post to the rails group?  
=R

---

<div class="post-metadata">

**Author:** ![anukulsinghal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@anukulsinghal](https://www.ruby-forum.com/u/anukulsinghal)\
**Post date:** [July 20, 2008, 1:22pm UTC](https://www.ruby-forum.com/t/using-insert-statement-in-active-record/143521/3 "2008-07-20T13:22:28Z")

</div>

Try:

class TestTable \< ActiveRecord::Base  
set\_table\_name ‘testTable’  
end

TestTable.new(:name=\>‘stuff’).save
