Not as elegant as John’s, but for some reason current.siblings
returns an empty array.
FWIW, the problem wasn’t that current.siblings was returning null.
Rather, the problem was that current.siblings returns a list that
doesn’t include the current page [1], so siblings.index(current) was
returning null. Calling “self_and_siblings” instead of “siblings”
works fine. Here’s the corrected version:
class Behavior::Base
define_tags do
tag "next" do |tag|
current = tag.locals.page
by = tag.attr['by'] || 'title'
siblings = current.self_and_siblings.sort_by { |page|
page.attributes[by] }
index = siblings.index(current)
next_page = siblings[index + 1]
if next_page
tag.locals.page = next_page
tag.expand
end
end
tag "previous" do |tag|
current = tag.locals.page
by = tag.attr['by'] || 'title'
siblings = current.self_and_siblings.sort_by { |page|
page.attributes[by] }
index = siblings.index(current)
previous = siblings[index - 1]
if previous
tag.locals.page = previous
tag.expand
end
end
There was no radiant/app directory so I’ve created it and its
behaviors child. I now get these errors:
Sorry, Dave, I should have been more clear. In your Radiant
installation (wherever that is), find the app directory, in which
there should be a behaviors directory. For example, if you installed
radiant in /home/dave/foo/radiant-0.5.2, you should put the
00_next_previous_behavior.rb in /home/dave/foo/radiant-0.5.2/app/
behaviors/.
Ah, another issue caused by using the gem installation then.
There was no radiant/app directory so I’ve created it and its
behaviors child. I now get these errors:
Sorry, Dave, I should have been more clear. In your Radiant
installation (wherever that is), find the app directory, in which
there should be a behaviors directory. For example, if you installed
radiant in /home/dave/foo/radiant-0.5.2, you should put the
00_next_previous_behavior.rb in /home/dave/foo/radiant-0.5.2/app/
behaviors/.
HTH,
Sean
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.