?
Solved

Rails console, saving objects

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 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