Rails: Get next / previous record
This is not at all how this is done. Your solution will load the entire set of IDs from the database, when it is only interested in two: The current ID, and the ID after or before it. What if there are 10,000,000 records? You'll create an array of 10 million integers, when all you need are two. You should absolutely not implement this as a select id from [table] order by [whatever] and process the entire table in Ruby, when a simple select * from [table] where id > [current] order by [whatever] limit 1 does the same job and returns a single record.