Forum: Ruby on Rails very basic newbie question!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Les N. (Guest)
on 2006-03-09 02:56
Bringing up (trying!) my first rails app... no OO experience

the scaffold generator automatically creates new activerecord objects
for the create/edit form using:

def new
  @schoolclass = Schoolclass.new
end

I wanted to initialize the object, so I added to the object creation
statement as follows:

  @schoolclass = Schoolclass.new(:day=>1, :start_time=>"2006:01:01
00:00:00, :description=>"enter description here")

I was expecting that I could access the attributes of @schoolclass with
(e.g.) @schoolclass.day .A breakpoint right after the object creation
allows me to see the initialized attributes using @schoolclass.inspect,
BUT when I look at individual attribues using (e.g.) @schoolclass.day or
@schoolclass[:day] or @schoolclass["day"] , they are all NIL.

What am I not seeing here? This exactly follows the example in the
ActiveRecord::Base documentation! How can I access the initialized
object attributes?

thanks in advance for any light you can shed!

Les
M Daggett (Guest)
on 2006-03-09 20:03
(Received via mailing list)
hi les
You may want to try schoolclass.create() instead of new() because new
doesn't store the record until you explicitly call the save function for
example schoolclass.save()

hope that makes sense and is the answer you were looking for.
Mark
This topic is locked and can not be replied to.