Class: PiggybakTaxonomy::NavigationController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/piggybak_taxonomy/navigation_controller.rb

Instance Method Summary collapse

Instance Method Details

#recursive_path(paths, nodes) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/piggybak_taxonomy/navigation_controller.rb', line 14

def recursive_path(paths, nodes)
  return nodes if paths.empty?
  first = paths.shift
  node = NavigationNode.find_by_slug(first)
  if node && (nodes.empty? || node.parent == nodes.last) && !(nodes.empty? && !node.parent.nil?)
    nodes << node
    nodes = recursive_path(paths, nodes) 
  end
  return nodes
end

#showObject



3
4
5
6
7
8
9
10
11
12
# File 'app/controllers/piggybak_taxonomy/navigation_controller.rb', line 3

def show
  paths = params[:path].split('/')
  nodes = recursive_path(paths, [])
  if nodes.empty?
    redirect_to main_app.root_url, :status => 301
  elsif nodes.size != params[:path].split('/').size
    redirect_to piggybak_taxonomy_url(:path => nodes.last.nav_path), :status => 301 
  end
  @node = nodes.last
end