# Adding record in database table

**URL:** <https://www.ruby-forum.com/t/adding-record-in-database-table/176348>\
**Category:** Rails\
**Created:** [September 29, 2009, 11:37am UTC](https://www.ruby-forum.com/t/adding-record-in-database-table/176348 "2009-09-29T11:37:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [September 29, 2009, 11:37am UTC](https://www.ruby-forum.com/t/adding-record-in-database-table/176348/1 "2009-09-29T11:37:40Z")

</div>

Hi,  
I have a question that Is it possible to add record into the database  
table without adding the model for that?

E.g. I have a table customers. And I haven’t created a model for that.  
Can I add a record into that table bu doing “cust=Custome.new cust.save”

Any help appreciated.  
Thanks,  
Tushar

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [September 29, 2009, 12:44pm UTC](https://www.ruby-forum.com/t/adding-record-in-database-table/176348/2 "2009-09-29T12:44:39Z")

</div>

2009/9/29 Tushar G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi,  
> I have a question that Is it possible to add record into the database  
> table without adding the model for that?
> 
> E.g. I have a table customers. And I haven’t created a model for that.  
> Can I add a record into that table bu doing “cust=Custome.new cust.save”

You can’t do Customer.new unless the Customer class is defined.  
Otherwise how would ruby know what to do?  
All you need is models/customer.rb containing

class Customer \< ActiveRecord::Base  
end

Provided the customer table meets the normal Rails conventions  
(primary key id and so on).

Colin

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [September 30, 2009, 4:37am UTC](https://www.ruby-forum.com/t/adding-record-in-database-table/176348/3 "2009-09-30T04:37:20Z")

</div>

The model was used for controller connected database.Otherwise, you can  
use  
straight SQL with ActiveRecord::Base.connection.execute.I would like to  
use  
model

On Tue, Sep 29, 2009 at 5:37 PM, Tushar G. \<  
removed\_email\_address@domain.invalid\> wrote:

> ## Tushar
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Sons of Gondor, of Rohan, my brothers!  
I see in your eyes the same fear that would take the heart of me.  
A day may come when the courage of men fails when we forsake our friends  
and  
break all bonds of fellowship.  
But this is not this day.  
And hour of wolves and shattered shields when the age of Men comes  
crashing  
down. But this is not this day!  
This day we fight! By all that you hold dear on this good earth, I bid  
you  
stand! Men of the West!

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [September 30, 2009, 3:11am UTC](https://www.ruby-forum.com/t/adding-record-in-database-table/176348/4 "2009-09-30T03:11:51Z")

</div>

If you don’t want to create a model you can use straight SQL with  
ActiveRecord::Base.connection.execute. I would create the model,  
though. It would be the hell of a lot simpler and cleaner.

On Sep 29, 5:37 am, Tushar G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
