2016-08-18 43 views
1

升級到Rails 5.0穩定版後,似乎無法讀取序列化列。Rails 5序列化數據庫列:NoMethodError:未定義的方法`[] ='爲零:NilClass

class PaymentNotification < ActiveRecord::Base 
    serialize :raw_IPN 
    ... 
end 

在數據庫中raw_IPN樣子:

--- !ruby/hash:ActionController::Parameters 
address_status: confirmed 
subscr_date: 12:42:39 Dec 20, 2015 PST 
payer_id: 123 
address_street: 1 Main St 
mc_amount1: '6.00' 
mc_amount3: '12.00' 
charset: windows-1252 
address_zip: '123' 
first_name: Test 
reattempt: '1' 
address_country_code: US 
address_name: Test Buyer 
notify_version: '3.8' 
subscr_id: I-123123123 
custom: '2' 
payer_status: verified 
business: [email protected] 
address_country: United States 
address_city: San Jose 
verify_sign: 123-12312312321312.2JohI99Xp56cvu9zc 
payer_email: [email protected] 
btn_id: '123' 
last_name: Buyer 
address_state: CA 
receiver_email: [email protected] 
recurring: '1' 
txn_type: subscr_signup 
item_name: asd 
mc_currency: EUR 
item_number: asd 
residence_country: US 
test_ipn: '1' 
period1: 12 M 
period3: 12 M 
ipn_track_id: 111 
controller: payment_notifications 
action: create 

錯誤:(在控制檯測試)

p = PaymentNotification.last 
PaymentNotification Load (0.1ms) SELECT `payment_notifications`.* FROM `payment_notifications` ORDER BY 
`payment_notifications`.`id` DESC LIMIT 1 

NoMethodError: undefined method `[]=' for nil:NilClass

堆棧跟蹤:

actionpack (5.0.0) lib/action_controller/metal/strong_parameters.rb:414:in `[]=' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:362:in `block in revive_hash' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:336:in `revive_hash' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:281:in `visit_Psych_Nodes_Mapping' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych/visitors/visitor.rb:16:in `visit' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych/visitors/visitor.rb:6:in `accept' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:32:in `accept' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:311:in `visit_Psych_Nodes_Document' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych/visitors/visitor.rb:16:in `visit' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych/visitors/visitor.rb:6:in `accept' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:32:in `accept' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych/nodes/node.rb:38:in `to_ruby' 
    /home/frexuz/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych.rb:253:in `load' 
    activerecord (5.0.0) lib/active_record/coders/yaml_column.rb:24:in `load' 
    activerecord (5.0.0) lib/active_record/type/serialized.rb:18:in `deserialize' 
    activerecord (5.0.0) lib/active_record/attribute.rb:140:in `type_cast' 
    activerecord (5.0.0) lib/active_record/attribute.rb:38:in `value' 
    activerecord (5.0.0) lib/active_record/attribute_set.rb:42:in `fetch_value' 
    activerecord (5.0.0) lib/active_record/attribute_methods/read.rb:66:in `_read_attribute' 
    activerecord (5.0.0) lib/active_record/attribute_methods/read.rb:36:in `__temp__271677f59405e4' 
    app/admin/payment_notifications.rb:17:in `block (3 levels) in <top (required)>' 

回答

3

此問題已在5-0穩定分支中修復。

解決方案: gem 'rails', github: "rails/rails", branch: '5-0-stable'bundle update rails直到他們發佈一個新的寶石版本。

+0

我也可以在rails 5.0.0.1中確認這個問題。回到分支建議,不再收到錯誤。 – nateleavitt

相關問題