My app has Photos that belong to Users.
In a photo#show view I\'d like to show \"More from this user\", and show a next and previous photo from that user. I would be
Modify your app/models/application_record.rb to the following code:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def next
self.class.where("id > ?", id).order("id ASC").first || self.class.first
end
def previous
self.class.where("id < ?", id).order("id DESC").first || self.class.last
end
end
Then you can use next() and previous() in all your models.