Show parents subpages if on a subpage

I am trying to display subpages from the subpages parent on a subpage.
The code between the lines doesn’t work for me. Does anyone has an
idea what would be a better code?
pages and subpages are in the same controller.

@page = Page.find_by_name(params[:name])

if @page.respond_to?(‘subpages’)
@subpages = @page.subpages

elsif @page.parent.respond_to?(‘subpages’)
@subpages = @page.parent.subpages
end

end

application.html.erb

for page in @page
show link to each page…
end

for page in @subpages
show link to each subpage…
end

Should acts_as_tree help me out?

Lasse wrote:

Should acts_as_tree help me out?

Hi,
As you need hierarchical structure. and straight forward parent ->
child relationship so, you will use acts_as_tree.

Lasse wrote:

Should acts_as_tree help me out?

I’m not sure. But what doesn’t work about your original code?

Anyway, if you need a tree plugin, skip acts_as_tree and use
awesome_nested_set. It’s far more efficient for reads.

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]