Say I’ve got a Questions and Answer model and I pull all the answers to a specific question.
I can easily do an each_with_index to and figure out what the index or “placement” of an answer is (in relation to the other answers to that specific question).
But, say I want to get a specific answer…how could I still figure out what the index of that answer is in relation to all the other answers associated with a specific question.
Example Answer data:
ID text question_id
23 awesome 3
27 boooyah 3
38 snap 3
If I did Answer.find(27) how can I figure out that record is the second item (assuming I’m ordering by ID…though I could order by any field).
1 Answer