Rails 5 serializing a database column: NoMethodError: undefined method `[]=' for nil:NilClass
Rails 5 serializing a database column: NoMethodError: undefined method `[]=' for nil:NilClass
升级到 Rails 5.0 稳定版后似乎无法读取序列化专栏。
class PaymentNotification < ActiveRecord::Base
serialize :raw_IPN
...
end
a 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: payments-facilitator@test.com
address_country: United States
address_city: San Jose
verify_sign: 123-12312312321312.2JohI99Xp56cvu9zc
payer_email: payments-buyer@test.com
btn_id: '123'
last_name: Buyer
address_state: CA
receiver_email: test@email.com
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)>'
此问题已在 5-0-stable 分支中修复。
解决方法:
gem 'rails', github: "rails/rails", branch: '5-0-stable'
和 bundle update rails
直到他们发布新的 gem 版本。
升级到 Rails 5.0 稳定版后似乎无法读取序列化专栏。
class PaymentNotification < ActiveRecord::Base
serialize :raw_IPN
...
end
a 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: payments-facilitator@test.com
address_country: United States
address_city: San Jose
verify_sign: 123-12312312321312.2JohI99Xp56cvu9zc
payer_email: payments-buyer@test.com
btn_id: '123'
last_name: Buyer
address_state: CA
receiver_email: test@email.com
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)>'
此问题已在 5-0-stable 分支中修复。
解决方法:
gem 'rails', github: "rails/rails", branch: '5-0-stable'
和 bundle update rails
直到他们发布新的 gem 版本。