ruby / rails:TypeError:无法将Symbol转换为Integer

时间:2015-04-01 11:37:32

标签: ruby-on-rails ruby

我试图更新我的Representation属性ivpn& idirect(来自csv文件,通过rake任务,但我只是打印在这里只是程序的内容)并得到TypeError:

# in Rails Console:
representation = Representation.where(id: 977)
# => Representation_id: 977, ivnp: false, idirect: false

rows = Hash.[:ivpn => "", :idirect => "x"] # originally rows are coming from csv-file

representation.update_attributes! ivpn: rows.any?{|r| r[:ivpn].present?}, idirect: rows.any? {|r| r[:idirect].present?}

TypeError: can't convert Symbol into Integer
        from (irb):42:in `[]'
        from (irb):42:in `block in irb_binding'
        from (irb):42:in `each'
        from (irb):42:in `any?'

我在这里失踪了什么?

1 个答案:

答案 0 :(得分:0)

试试这个:

representation.update_attributes! ivpn: rows.any?[{|r| r[:ivpn].present?}], idirect: rows.any? [{|r| r[:idirect].present?}]
相关问题