0

I just learned to use ActiveRecord and change things in the database. In the video I watched it instructed me to use this command in the terminal (after writing rails console):

subjects = Subject.new(:name => "First Chapter", :position => 1, visible => true)

I was wondering what exactly the role of the word subjects in the beginning is, and what the role of the second Subject (capitalized) is. I believe the capitalized one is a class, but how exactly does everything work? could I just write a= Subjects.new... or does it have to say subjects?

Also, do singular and plural matter? How about capital and non capital? I got really confused when to use capital and when to use plural.

Finally, I used subject.destroy to delete an entry. Does that destroy the last object that I found using subject.find(2) for example? And is it possible to recover the data after deleting it?

Final final question is, after using subject.destroy I did a new entry but it appeared to have skipped one ID. I erased ID=2 entry, and the next I entered got the ID 3 (which is logical). If I write subject = Subject.find(2) it tells me there is nothing found. So is there a way to shift the entry with ID 3 to the position of ID 2? That would close the hole, since on ID 2 there is nothing anyway.

Sorry for the many questions, but with little experience in ruby and SQL it's quite tough.

FYI my table looks like this now:

Subject.all

=> [< Subject id: 1, name: "Initial Subject", position: 1, visible: true>, 

< Subject id: 3, name: "Second Subject", position: 2, visible: false>, 

< Subject id: 4, name: "third Subject", position: 3, visible: false>,

< Subject id: 5, name: "Revised Subject", position: 4, visible: true>]
1
  • 1
    I would ask many separate questions rather than putting them in this 1 chunk of question. Commented Jul 8, 2011 at 20:56

1 Answer 1

1

I think you will be able to answer most of your questions by reading through official guide.

http://guides.rubyonrails.org/getting_started.html

Sign up to request clarification or add additional context in comments.

1 Comment

Can anyone give me an explanation to this, really in troublee, even after reading the guide.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.