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 )
精彩评论