rails activerecord 中的 insert ( why array.insert works in Ruby but not in Rails?)

访问量: 1273

因为 Rails 中返回的是 ActiveRecord.relationship,  而不是raw Array.

e.g.
# in irb
[2,3,4].insert(1, 'a') # => [2,'a', 3, 4]

# in Rails
models = SomeModel.where(...)
models.insert(1,'b')  # wrong argument: 2 for 1 
models.to_a.insert(1,'b')  # good 

订阅/RSS Feed

Subscribe

分类/category