Hi Everyone,
I just found this forum today and I’m having trouble with a rails
tutorial I’m working on. On all other rails console commands it runs
when I hit enter such as:
“>> subject.new_record?
=> true”
However when I try to save a record using:
subject = Subject.new(:name => “First Subject”, :position => 1", :visible =>
true)
Nothing happens. I tried create as well. When I hit enter it just puts
an enter and doesn’t run the command which returns. Any clue what I’m
doing wrong?
On Sat, Nov 26, 2011 at 14:09, Steve Mr. [email protected] wrote:
On all other rails console commands it runs
when I hit enter such as:
“>> subject.new_record?
=> true”
However when I try to save a record using:
subject = Subject.new(:name => “First Subject”, :position => 1", :visible =>
true)
That won’t save a record. It will only create an object. To save it
as a database record, you need to do subject.save – and that also
assumes that the class inherits from ActiveRecord, you’ve created the
table in the database, etc.
Nothing happens. I tried create as well. When I hit enter it just puts
an enter and doesn’t run the command which returns. Any clue what I’m
doing wrong?
Does it do absolutely nothing, not even tell you something like:
=> #<Subject:0x00000100a218a8 name=“dave”, position=“reclining”,
visible=true>
? That is indeed odd. Can you post the code of the class, at least
the initializer?
-Dave
–
LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern
languages.
Where: Northern Virginia, Washington DC (near Orange Line), and remote
work.
See: davearonson.com (main) * codosaur.us (code) * dare2xl.com
(excellence).
Specialization is for insects. (Heinlein) - Have Pun, Will Babble!
(Aronson)
Subject.new only create a new object in memory, to persist in the
database
you should to use subject.save or directly Subject.create(:name =>
“First
Subject”, :position => 1", :visible => true)
2011/11/26 Steve Mr. [email protected]
–
You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
–
Fernando A.
www.fernandoalmeida.net
On 26 November 2011 19:09, Steve Mr. [email protected] wrote:
However when I try to save a record using:
subject = Subject.new(:name => “First Subject”, :position => 1", :visible =>
true)
Nothing happens.
You’ve got an extra quote in there after :position…
On 26 November 2011 19:43, Steve Mr. [email protected] wrote:
wow. The quote was the issue. Unbelievable. Thanks. I’m back to cranking
out this tutorial
The reason it did not do anything was because you had not entered a
complete statement (the extra quote meant that the last stuff on the
line appeared to be a quoted string) so it was waiting for you to
enter the rest of the statement. I imagine it prompted you with a >
or similar.
Colin
wow. The quote was the issue. Unbelievable. Thanks. I’m back to cranking
out this tutorial