Rails 3.1.0.rc4 + Postgres - cannot read or write to the database after reboot

I just started writing an application using the latest version of Rails and PostgreSQL. I created the database, added the necessary gem, configured the database.yml file and started with two models - User (for this, Devise was used for authentication) and Group. I created an additional controller for the start page (simple - only to display a list of links). Everything seemed beautiful, I was able to add test data to the database until I returned this morning and did not want to continue working.

While I stayed on the main page, everything looked like yesterday. But when I tried to access the list of groups, I got the following error:

Routing Error You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.map 

There was no additional information on the page, so I looked at the Webrick console and saw the following:

 ActionController::RoutingError (You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.map): app/controllers/groups_controller.rb:1:in `<top (required)>' 

The first line of my controller, as usual:

 class GroupsController < ApplicationController 

I looked at other actions and the result was the same: unexpected nil object. The same problem occurred while trying to perform any action for the user.

I suspected it was a database problem (because it didnโ€™t affect the controller, which didnโ€™t use the database at all), so I went to the rails console to find out if I could add entries manually. I could not.

 ruby-1.9.2-p180 > group = Group.new (some SQL) NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.map from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/persistence.rb:320:in `attributes_from_column_definition' from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/locking/optimistic.rb:69:in `attributes_from_column_definition' from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/base.rb:1525:in `initialize' from (irb):1:in `new' from (irb):1 from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/commands/console.rb:45:in `start' from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/commands/console.rb:8:in `start' from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/commands.rb:40:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>' 

I looked at the topmost file (persistence.rb) and searched for line 320.

 319: def attributes_from_column_definition 320: Hash[self.class.columns.map do |column| 321: [column.name, column.default] 322: end] 323: end 

This definition gave me a little idea of โ€‹โ€‹what might happen, so I ran another command in the console (Group.inspect) and I got an error in the following line:

 attr_list = columns.map { |c| "#{c.name}: #{c.type}" } * ', ' 

It seems like I cannot access the columns of my table, but I have no idea why. I am logged in as the same user on the same machine using the same operating system and kernel. Out of curiosity, I created another application, and it did not work after rebooting.

I spent four hours looking for an answer, but I could not find anything related. What can cause this problem and how to fix it?

+4
source share
2 answers

I found the culprit: a small gem called "automatic_foreign_key" I used to automatically detect foreign keys. When I roll back the changes made, delete them and manually change the table, I had the application again.

Thank you all for your help!

+1
source

Perhaps the group is a reserved word in this version of postgresql or rails. rails-3.1.0-rc4 is the latest version of rails. Create another dead model just to test it.

0
source

All Articles