开发者

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

I've just started to write an application using the latest version of Rails and PostgreSQL. I created the database, added required gem, configured database.yml file and started with two models - User (this one used Devise for authentication) and Group. I created an additional controller for start page (simple one - only to display list of links). Everything seemed fine, I was able to add test data to the database - until I came back this morning and wanted to continue work.

As long as I stayed on the home page, everything looked just like yesterday. But when I tried to access group list, 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 informations on the page, so I looked into 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 is, as usual:

class GroupsController < ApplicationController

I looked at the other actions, and the result was the same: unexpected nil object. Same issue occured w开发者_开发知识库hile trying to perform any action on User.

I suspected it's a database problem (because it didn't affect the controller that wasn't using database at all), so I went to rails console to see if I could add entries manually. I couldn't.

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 into the most top 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 what might be happening, so I ran one more command in the console (Group.inspect) and I got error on the following line:

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

It seems like I'm not able to access the columns of my table, but I have no idea why. I'm 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 didn't work after the reboot either.

I've spent now four hours looking for answer, but I couldn't find anything related. What might be causing this problem and how to fix it?


I have found the guilty one: small gem called 'automatic_foreign_key' I used to automatically detect foreign keys. When I rollback the changes it made, removed it and altered the table manually, I had my application working again.

Thank you all for help!


Maybe Group is a reserved word in this version of postgresql or rails. rails-3.1.0-rc4 is the most fresh version of rails. Generate another dead simply model to check it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜