Working with rails console

I am using rvm on the ubuntu. I am following the rails tutorial from
Lynda.com
I was on the section of working in the rails console when i got the
following errors :-

I gave the command rails console

[email protected]:~/Nitin/Sites/app$ rails console

Loading development environment (Rails 3.2.1)

1.9.2p290 :001 > subject=Subject.new
=> #<Subject id: nil, subject_name: nil, position: nil, visible: false,
created_at: nil, updated_at: nil>

1.9.2p290 :002 > subject.new_record?
=> true

1.9.2p290 :003 > subject.name = “History”
NoMethodError: undefined method name=' for #<Subject:0x8ab6e9c> from /home/nitin/Nitin/Sites/app/mysql2/ruby/1.9.1/gems/activemodel-3.2.1/lib/active_model/attribute_methods.rb:407:inmethod_missing’
from
/home/nitin/Nitin/Sites/app/mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:126:in
method_missing' from (irb):3 from /home/nitin/Nitin/Sites/app/mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands/console.rb:47:instart’
from
/home/nitin/Nitin/Sites/app/mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in
start' from /home/nitin/Nitin/Sites/app/mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:41:in<top (required)>’
from script/rails:6:in require' from script/rails:6:in
1.9.2p290 :004 > subject.name = “History”
NoMethodError: undefined method name=' for #<Subject:0x8ab6e9c> from /home/nitin/Nitin/Sites/app/mysql2/ruby/1.9.1/gems/activemodel-3.2.1/lib/active_model/attribute_methods.rb:407:inmethod_missing’
from
/home/nitin/Nitin/Sites/app/mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:126:in
method_missing' from (irb):4 from /home/nitin/Nitin/Sites/app/mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands/console.rb:47:instart’
from
/home/nitin/Nitin/Sites/app/mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in
start' from /home/nitin/Nitin/Sites/app/mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:41:in<top (required)>’
from script/rails:6:in require' from script/rails:6:in

When I tried to create a subject name I got the above errors.
I couldn’t find the solution on google. Please help me if anyone has
encountered such an error and solved it.

On Mon, Feb 13, 2012 at 9:43 AM, Nitin A. [email protected] wrote:

Loading development environment (Rails 3.2.1)

1.9.2p290 :001 > subject=Subject.new
=> #<Subject id: nil, subject_name: nil, position: nil, visible: false,
created_at: nil, updated_at: nil>

Your variable name is “subject_name”

1.9.2p290 :002 > subject.new_record?
=> true

1.9.2p290 :003 > subject.name = “History”
NoMethodError: undefined method `name=’ for #Subject:0x8ab6e9c
from

Here, you want to use a variable with name “name”.

Could you try:

subject.subject_name = “History”

You could also change the name of the column with a migration.

HTH,

Peter


*** Available for a new project ***

Peter V.
http://twitter.com/peter_v
http://rails.vandenabeele.com
http://coderwall.com/peter_v

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs