Hello!
It is happening a very weird thing when I save a model in rails 3.1
Same project in development / production
There is a simple model City with 2 fields (name / state).
development console
city = City.new(:name => "Sao Paulo", :uf => "SP")
city.save (true, no validations errors and record is created in database)
if I call “city.id”, I get real value of ID saved in database, e.g. 123.
It is working fine in development.
production console
city = City.new(:name => "Sao Paulo", :uf => "SP")
city.save (true, no validations errors and record is created in database)
if I call “city.id”, I get value equal 0 (different from value created automatically in database)
City.last (check if record is created in database...)
<City id: 22257, name: "Sao Paulo", uf: "SP", created_at: "2011-11-23 00:52:53", updated_at: "2011-11-23 00:52:53">
The record is created in database but not returns ID after call save/create. Did anyone see this before? This is the first time I see this behavior in production. It happens to every model in project. I used model City because it is the simplest one.
I am running rails 3.1.
Thanks for help!
I found the solution!!! I was using ‘mysql’ gem insted ‘mysql2’. When I changed to mysql2 (in Gemfile and database.yml adapter), everything worked fine. It is probably an incompatibility issue betwen gem ‘mysql’ and rails 3.1. Thanks you all for help!