Skip to content

Instantly share code, notes, and snippets.

@neotericdesign
Created April 26, 2012 21:06
Show Gist options
  • Save neotericdesign/2503251 to your computer and use it in GitHub Desktop.
Save neotericdesign/2503251 to your computer and use it in GitHub Desktop.
def next
page = self.class.choose(self, 'rgt >', :first)
page ||= self.class.choose(self, 'lft <', :first)
end
def prev
page = self.class.choose(self, 'lft <', :last)
page ||= self.class.choose(self, 'rgt >', :last)
end
class << self
def choose(page, position_condition, pick)
position_method = position_condition.split.first
results = where("#{position_condition} ? AND depth = ? AND parent_id = ?",
page.send(position_method.to_sym),
page.depth,
page.parent_id)
.live
.in_menu
.order(position_method) # ASC is default
results.send(pick)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment