Solved

Rails console, saving objects

Posted on 2008-10-05
1
1,002 Views
Last Modified: 2013-11-13
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. Is there a way to check if I asked?

I do know if I typed craeted_at instead of created_at or updetad_at instead of updated_at. Is there a way to 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?
0
Comment
Question by:locke1994
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
wesgarrison earned 375 total points
ID: 22647317
Check out your migration in db/migrate.
There should be one called "create_stories" or something similar.

You can change that file and then rerun the migrations with 'rake db:reset'.

If you want to delete an object, just call the destroy on it or via the class:

# delete an instance
story = Story.find(2)
story.destroy
 
# delete via class method
Story.destroy(2)
 
# Both do the exact same thing

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
extending out dates 4 299
Free Ruby on Rails hosting 4 537
git - conflict 5 224
ruby on rails date formatting 1 174
I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question