I have this which nicely gives me next and previous items:
scope :next, lambda {|id| where("id > ?",id).order("id ASC") }
scope :previous, lambda {|id| where("id < ?",id).order("id DESC") }
def next
Item.next(self.id).first
end
def previous
Item.previous(self.id).first
end
In my view:
<%= link_to @item.previous, title: "xxx" do %>
<span class="glyphicon glyphicon-chevron-left" style="color:#eeeeee"></span>
<% end %>
I would like to enhance above so that I don't just get the next/previous item but the next/previous item which has the same :source_id (my item's have source_id).
Found two similar question here but can't apply it to my example:
How to have multiple conditions in a named scope?
Rails scope with 2 where clauses
TIA!