Rails 3: Error saving an object with no useful information

Hey,

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:inmethod_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:inflatten’
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:inrescue
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:intransaction' from D:/ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0.rc/lib/active_record/transactions.rb:204:intransaction’
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:insave!’
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:instart’
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:inrequire’
from script/rails:6:in `’

Is it possible to show more debug information or something like that?

No one? I’m kinda desperate with that problem…

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.

I’m using console and I restarted and reloaded it a couple of times.

Rails 3.0.0.rc and Ruby 1.9.2

Sorry, I didn’t pay too much attention to the subject. My apps run
under 2.3.5 and that might make things different, though.

Heinz S. wrote:

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:inmethod_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.

No, exactly that is the problem. I never used .to_ary in my code. Where
can I see the debug log of the console?

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

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