Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Rails console, saving objects

Posted on 2008-10-05
1
Medium Priority
?
1,018 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 1500 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 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