开发者

How do I perform a ActiveRecord search and remove everyone up to a specific record from an array?

开发者 https://www.devze.com 2023-04-12 19:04 出处:网络
I just tried performing a method, and it failed after hitting a specific object. Knowing the email开发者_运维技巧 attribute of that object, how can I create an array, and limit the return to only tho

I just tried performing a method, and it failed after hitting a specific object.

Knowing the email开发者_运维技巧 attribute of that object, how can I create an array, and limit the return to only those objects that are after that specific object?

This is a Rails 2 project


I'd say:

your_array.take_while {|elt| elt.email != email }

Or for 1.9.2:

your_array.slice_before{|elt| elt.email == email }.first


if you have an array try something like

irb(main):030:0> ary = [ 1, 2, 3, 4, 5, 6, 7 ]
=> [1, 2, 3, 4, 5, 6, 7]
irb(main):031:0> ary.values_at( ary.index(4)..-1 )
=> [4, 5, 6, 7]


This may help, as where will return all records after the id == id

id = SomeModel.where( :email => 'email_you@kn.ow' ).first.id

SomeModel.where( "id > ?", id )
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号