无法在生产环境中创建模型对象

时间:2015-05-21 08:43:43

标签: ruby-on-rails ruby ruby-on-rails-3 amazon-web-services

我在rails中创建了一个模型类,并在本地开发和生产环境中测试了它们。 但是,我将rails应用程序部署到AWS并发现超级奇怪的问题。 我不能再使用我的模型了。

例如,

Loading production environment (Rails 4.1.6)
Mgmt_Server :001 > defined?(Game)
=> "constant" 
Mgmt_Server :002 > Game.create
NoMethodError: undefined method `[]' for nil:NilClass ... etc

开发AWS

Loading development environment (Rails 4.1.6)
Mgmt_Server :004 > Game.create!
(0.1ms)  BEGIN
SQL (0.2ms)  INSERT INTO `games` (`created_at`, `updated_at`) VALUES   ('2015-05-21 08:41:16', '2015-05-21 08:41:16')
(2.0ms)  COMMIT
=> #<Game id: 2, name: nil, description: nil, platform: nil, state: nil, exe: nil, launch_command: nil, terminate_command: nil, waiting_queue_size: nil, allow_play: false, created_at: "2015-05-21 08:41:16", updated_at: "2015-05-21 08:41:16"> 

完全不知道根本原因...... 我非常确定db site beacuase中没有问题我使用相同的db进行测试。

game.rb

class Game < ActiveRecord::Base
  has_many :game_defaults
  has_many :game_save
end

回溯

ubuntu@ip-10-0-0-21:~/MgmtService/Mgmt_Server/config$ rails c production
Loading production environment (Rails 4.1.6)
Mgmt_Server :001 > Game
 => Game (call 'Game.connection' to establish a connection) 
Mgmt_Server :002 > Game.all
 => #<ActiveRecord::Relation []> 
Mgmt_Server :003 > Game.create
NoMethodError: undefined method `[]' for nil:NilClass
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/beefcake-1.0.0/lib/beefcake.rb:229:in `block in initialize'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/beefcake-1.0.0/lib/beefcake.rb:228:in `each'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/beefcake-1.0.0/lib/beefcake.rb:228:in `initialize'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/inheritance.rb:30:in `new'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/inheritance.rb:30:in `new'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/persistence.rb:33:in `create'
    from (irb):3
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/commands/console.rb:90:in `start'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/commands/console.rb:9:in `start'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/commands.rb:17:in `<top (required)>'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
... 1 levels...
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `block in load'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/spring-1.3.6/lib/spring/commands/rails.rb:6:in `call'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/spring-1.3.6/lib/spring/command_wrapper.rb:38:in `call'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/spring-1.3.6/lib/spring/application.rb:183:in `block in serve'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/spring-1.3.6/lib/spring/application.rb:156:in `fork'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/spring-1.3.6/lib/spring/application.rb:156:in `serve'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/spring-1.3.6/lib/spring/application.rb:131:in `block in run'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/spring-1.3.6/lib/spring/application.rb:125:in `loop'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/spring-1.3.6/lib/spring/application.rb:125:in `run'
    from /home/ubuntu/.rvm/gems/ruby-2.1.2/gems/spring-1.3.6/lib/spring/application/boot.rb:18:in `<top (required)>'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'

TKS

(注)

我在game.rb =&gt;中做了一些改变。

class Game < ActiveRecord::Base
  has_many :game_defaults
  #has_many :game_save   (remove this line)
end

我可以在生产环境中成功创建模型。

ubuntu@ip-10-0-0-21:~/MgmtService/Mgmt_Server/app/models$ rails c production
Loading production environment (Rails 4.1.6)
Mgmt_Server :001 > Game.create
 => #<Game id: 1, name: nil, description: nil, platform: nil, state: nil, exe: nil, launch_command: nil, terminate_command: nil, waiting_queue_size: nil, allow_play: false, created_at: "2015-05-21 10:05:42", updated_at: "2015-05-21 10:05:42"> 

TKS。

1 个答案:

答案 0 :(得分:0)

尝试使用定义的DISABLE_SPRING=1环境变量,它似乎调用AR,后者又调用beefcake,如果没有后续序列化game_save对象的头数据,则无法初始化。

如果有助于重新部署--without development test