How to find index of array of records return from database in rails?

Puja

I am getting array of records from sql query now I want to find whether current users record is present in that array of records and at which position. So I wrote following query but it is returning null.

@top_score_cards = Score.group(:points).distinct.order("points DESC, updated_at DESC").where("points != ? And activity_id= ?",0,params[:@myActivity])#.limit(3)
@current_users_rank=@top_score_cards.index(current_user)

puts @current_users_rank 
aarkerio

You could try:

top_score_cards.include?(current_user.id)

you can use pluck to directly convert a database result into an array.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to return records from database using javalite?

From Dev

How to I select distinct records with ids from a database in Rails?

From Dev

Rails - how to group/map records from database into a string?

From Dev

Rails how to sort records from database in a specific order?

From Dev

How to return array from database in c#

From Dev

Lravel 5.1 How to find database records through a from?

From Dev

how to get array from database in rails

From Dev

rails how to find with no associated records

From Dev

How to create multiple records from array in Rails Console

From Dev

How to find ids of record from array of records using Ruby 2.0

From Dev

Return only repeated records from database

From Dev

Find records with the condition from other model rails

From Dev

How to return middle records in rails db?

From Dev

Rails: Find all records where string column contains all words from an array of strings

From Dev

How to store database records into hash ruby on rails

From Dev

How to Return two non-consecutive Index Values from an Array

From Dev

How to Return two non-consecutive Index Values from an Array

From Dev

How to return a single index from an array in a Meteor publication

From Dev

In Rails 4.1, how to find records by enum symbol?

From Dev

return index of array from return value of a method

From Dev

How could I return array and use it in anoher class from database

From Dev

Get all Rails records from an array of IDs

From Dev

Find text in array and return index number

From Dev

How to return all records that were added to the database within the last 7 days from current date

From Dev

How to find index of STRING array in Java from a given value?

From Dev

How to find the index of a subsection in an array from one string (python 3.4.2)

From Dev

How to find an index of a string(first three character) from an array

From Java

How to use lodash to find and return an object from Array?

From Dev

How to find, return and remove the maximum value from an array in Ruby?

Related Related

  1. 1

    How to return records from database using javalite?

  2. 2

    How to I select distinct records with ids from a database in Rails?

  3. 3

    Rails - how to group/map records from database into a string?

  4. 4

    Rails how to sort records from database in a specific order?

  5. 5

    How to return array from database in c#

  6. 6

    Lravel 5.1 How to find database records through a from?

  7. 7

    how to get array from database in rails

  8. 8

    rails how to find with no associated records

  9. 9

    How to create multiple records from array in Rails Console

  10. 10

    How to find ids of record from array of records using Ruby 2.0

  11. 11

    Return only repeated records from database

  12. 12

    Find records with the condition from other model rails

  13. 13

    How to return middle records in rails db?

  14. 14

    Rails: Find all records where string column contains all words from an array of strings

  15. 15

    How to store database records into hash ruby on rails

  16. 16

    How to Return two non-consecutive Index Values from an Array

  17. 17

    How to Return two non-consecutive Index Values from an Array

  18. 18

    How to return a single index from an array in a Meteor publication

  19. 19

    In Rails 4.1, how to find records by enum symbol?

  20. 20

    return index of array from return value of a method

  21. 21

    How could I return array and use it in anoher class from database

  22. 22

    Get all Rails records from an array of IDs

  23. 23

    Find text in array and return index number

  24. 24

    How to return all records that were added to the database within the last 7 days from current date

  25. 25

    How to find index of STRING array in Java from a given value?

  26. 26

    How to find the index of a subsection in an array from one string (python 3.4.2)

  27. 27

    How to find an index of a string(first three character) from an array

  28. 28

    How to use lodash to find and return an object from Array?

  29. 29

    How to find, return and remove the maximum value from an array in Ruby?

HotTag

Archive