mac:Project $ jruby script/console test
/Applications/NetBeans/NetBeans
6.7.app/Contents/Resources/NetBeans/ruby2/jruby-1.2.0/bin/jruby: line
52: [: too many arguments
Loading test environment (Rails 2.3.4)
p = Permission.new(:user_id => 1, :department_id => 6)
=> #<Permission id: nil, user_id: 1, department_id: 6, created_by: nil,
updated_by: nil, created_at: nil, updated_at: nil>
p.valid?
=> true
p.save
=> true
p.id
=> nil #I THOUGHT SAVE WAS ‘TRUE’?!
p.new_record?
=> false #Oh good it is in the DB, right?
p.id
=> nil #HOW?!
p.save
=> true
p.id
=> nil
p
=> #<Permission id: nil, user_id: 1, department_id: 6, created_by: nil,
updated_by: nil, created_at: “2009-12-01 14:41:10”, updated_at:
“2009-12-01 14:41:10”>
This is only happens in TESTING environment.
The record never shows up in the DB either. Why is rails lying to me?
MacOSX Snow Leopard
jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-06-24 rev 6586)
[x86_64-java]
Rails 2.3.4
Rake 0.8.7
MySQL 5.1.40
Hi Dan,
p is actually a method in Ruby. So, p() returns nil, and p.id means
the id() on nil. 
Use the names of your variables carefully
I wolud definitely avoid
names p, as well as methods/fields with name id.
Thanks,
–Vladimir
On Tue, Dec 1, 2009 at 9:45 PM, Dan O. [email protected] wrote:
=> true
p.id
“2009-12-01 14:41:10”>
MacOSX Snow Leopard
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Vlad,
Are you sure on this?
From looking at the steps taken and applying your logic the p.save and
others should return method missing then. Wouldn’t it?
When I run the above example in MRI and JRuby dev branch I get
expected behavior. (p.id works) Dan can you try an example with the
latest JRuby and see if the problem is fixed?
Jay
On Tue, Dec 1, 2009 at 4:23 PM, Vladimir S. [email protected]
wrote:
p.valid?
updated_by: nil, created_at: “2009-12-01 14:41:10”, updated_at:
http://xircles.codehaus.org/manage_email
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Fair enough! 
On Wed, Dec 2, 2009 at 9:46 AM, Vladimir S. [email protected]
wrote:
Use the names of your variables carefully
I wolud definitely avoid
Loading test environment (Rails 2.3.4)
p.id
This is only happens in TESTING environment.
http://xircles.codehaus.org/manage_email
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Hi Jay,
On Wed, Dec 2, 2009 at 2:18 PM, Jay McGaffigan [email protected]
wrote:
Vlad,
Are you sure on this?
Well, maybe not 100% sure
But every time I used p as a name for a
variable, sooner or later I got burned one way or another (weird
things like described in this thread), so I just don’t do that
anymore. Especially in jirb! 
Thanks,
–Vladimir
Thanks,
=> #<Permission id: nil, user_id: 1, department_id: 6, created_by: nil,
p.new_record?
p
–
http://xircles.codehaus.org/manage_email
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email