I'm kinda desperate cause I'm getting an error and have no idea how to
fix this since it doesn't give me any information hinting where the
problem is:
irb(main):054:0> reload!;User.last.save!
Reloading...
NameError: undefined local variable or method `to_ary' for
#<User:0x4ed5d20>
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.0.0.rc/lib/active_model/attribute_methods.rb:364:in
`method_missing'
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0.rc/lib/active_record/attribute_methods.rb:46:in
`method_missing'
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0.rc/lib/active_record/connection_adapters/abstract/database_statements.rb:296:in
`flatten'
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0.rc/lib/active_record/connection_adapters/abstract/database_statements.rb:296:in
`rollback_transaction_records'
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0.rc/lib/active_record/connection_adapters/abstract/database_statements.rb:177:in`rescue
in transaction'
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0.rc/lib/active_record/connection_adapters/abstract/database_statements.rb:162:in`transaction'
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0.rc/lib/active_record/transactions.rb:204:in
`transaction'
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0.rc/lib/active_record/transactions.rb:287:in
`with_transaction_returning_status'
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0.rc/lib/active_record/transactions.rb:242:in
`save!'
from (irb):54
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0.rc/lib/rails/commands/console.rb:44:in
`start'
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0.rc/lib/rails/commands/console.rb:8:in
`start'
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0.rc/lib/rails/commands.rb:23:in
`<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Is it possible to show more debug information or something like that?
Are you working from irb or the console? It seems that you are running
your code from irb (irb(main):054:0> reload!;User.last.save!) and you
might not have everything you need loaded.
I just tried User.last.save! from the console on one of my apps and it
works just fine.
irb(main):054:0> reload!;User.last.save!
Reloading...
NameError: undefined local variable or method `to_ary' for
#<User:0x4ed5d20>
from
D:/ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.0.0.rc/lib/active_model/attribute_methods.rb:364:in
`method_missing'
What is 'to_ary' supposed to be? Is that a method you added to User?
User appears to be an ActiveRecord::Base subclass and 'to_ary' is making
it into ActiveRecord's implementation of method_missing, which
apparently doesn't know what to do with the method with that name.
At least that's what I can glean from the stack trace.
I know it's silly but have you checked the log file(s)? If you are
working with the console in development mode it should give you all
information you might need to debug the problem.
Thinking about the problem a little more makes me believe that you
probably have code that looks like this:
u = User.find your_id_value # => Will produce a User object
u.to_ary # => This gives you an error
When you run to_ary against a user object you get an error but when
you run it against an array of users it works:
u = User.find :all # => Will produce an array of User objects
u.to_ary # => This works