Answer the question
In order to leave comments, you need to log in
How in Ruby on Rails can you determine which account is a record from the database?
For example, there is the last record in the table Table.last.
How to find out what number of element it is in the table?
Answer the question
In order to leave comments, you need to log in
Based on the fact that when we use the .all method relative to the model and get an array, then:
For example, we are looking for users, your_item_id = Table.last.id, we got id=45.
Now let's remove all the id records of the table, create an empty array all_items_ids = [], then write a block like Table.all.each { |item| all_items_ids.push(item.id }
Now we get the index, your_item_index = all_items_ids.index{ |id| id == your_item_id }
I wrote the first thing that came to mind, don't blame me
Better describe the task, I feel you went the wrong way.
Are you doing pagination? :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question