This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node < ActiveRecord::Base | |
| def parent | |
| if parent_id = path.last | |
| self.class.find(parent_id) | |
| else | |
| nil | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node < ActiveRecord::Base | |
| def ancestors | |
| if path.present? | |
| self.class.where(id: path) | |
| else | |
| self.class.none | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node < ActiveRecord::Base | |
| def siblings | |
| self.class.where(path: path) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node < ActiveRecord::Base | |
| def children | |
| self.class.where(path: path + [id]) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node < ActiveRecord::Base | |
| def descendants | |
| self.class.where(“:id = ANY(path)”, id: id) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NodesController < ActionController::Base | |
| def index | |
| @nodes = Node.roots | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ul> | |
| <%= render @nodes %> | |
| </ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <li> | |
| <%= link_to node.name, node %> | |
| <% if node.children.present? %> | |
| <ul> | |
| <%= render node.children %> | |
| </ul> | |
| <% end %> | |
| </li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NodesController < ActionController::Base | |
| def index | |
| @nodes = Node.roots.eager_load(:descendants) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html xmlns="http://www.w3.org/1999/xhtml" > | |
| <head> | |
| <title>A Sneak Peek at The Internet</title> | |
| </head> | |
| <body> | |
| <h1>A Sneak Peek at The Internet</h1> | |
| <p>Now hosted on <a href=“https://aws.amazon.com/“>Amazon Web Services</a>!</p> | |
| </body> | |
| </html> |