# Rails console, saving objects

**URL:** <https://www.ruby-forum.com/t/rails-console-saving-objects/150211>\
**Category:** Rails\
**Created:** [October 6, 2008, 4:22am UTC](https://www.ruby-forum.com/t/rails-console-saving-objects/150211 "2008-10-06T04:22:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raistlin\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9fc348/32.png) [@Raistlin\_M](https://www.ruby-forum.com/u/Raistlin_M)\
**Post date:** [October 6, 2008, 4:22am UTC](https://www.ruby-forum.com/t/rails-console-saving-objects/150211/1 "2008-10-06T04:22:58Z")

</div>

I was reading a book and following the instructions in it.

> > class Story \< ActiveRecord::Base; end  
> > =\> nil
> 
> > story = Story.new  
> > =\> #\<Story id: nil, name: nil, url: nil, created\_at: nil,  
> > updated\_at: nil\>
> 
> > story.class  
> > =\> Story(id: integer, name: string, link: string,  
> > created\_at: datetime, updated\_at: datetime)

I do not remember me asking for id, name, link or url, created\_at and  
updated\_at. I do know if I typed craeted\_at instead of created\_at or  
updetad\_at instead of updated\_at. How do I check whether i typed it  
right or wrong?

From the Rails console, I had to create a story class, one instance of  
it and save the object, but I created two, so I got a 2 output for a  
story.id input. How do I remove the second object from the database?

---

<div class="post-metadata">

**Author:** ![Raistlin\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9fc348/32.png) [@Raistlin\_M](https://www.ruby-forum.com/u/Raistlin_M)\
**Post date:** [October 6, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/rails-console-saving-objects/150211/2 "2008-10-06T21:18:43Z")

</div>

On Oct 5, 2008, at 7:22 PM, Raistlin M. wrote:

> created\_at: datetime, updated\_at: datetime)
> 
> I do not remember me asking for id, name, link or url, created\_at and  
> updated\_at.

At some point you must have created a “stories” table in your database  
with those fields. Rails (technically ActiveRecord) finds this based  
on the name of your class (singular version of the table by default).

> I do know if I typed craeted\_at instead of created\_at or  
> updetad\_at instead of updated\_at. How do I check whether i typed it  
> right or wrong?

It should complain about the method not being there.

> From the Rails console, I had to create a story class, one instance of  
> it and save the object, but I created two, so I got a 2 output for a  
> story.id input. How do I remove the second object from the database?

Story.destroy(2)

Note that that ‘2’ is the _id_ of the record you want to remove. Has  
nothing to do with it being the ‘second’ object.
