diff options
| author | realtradam <[email protected]> | 2020-12-02 19:26:28 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2020-12-02 19:26:28 -0500 |
| commit | d13b636bd654244f894943c2968a7386e8379605 (patch) | |
| tree | 410809bae61eac943e1af19ecfd2c2f31143c796 /app/controllers/nodes_controller.rb | |
| download | rails-tree-style-activerecord-d13b636bd654244f894943c2968a7386e8379605.tar.gz rails-tree-style-activerecord-d13b636bd654244f894943c2968a7386e8379605.zip | |
initial
Diffstat (limited to 'app/controllers/nodes_controller.rb')
| -rw-r--r-- | app/controllers/nodes_controller.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb new file mode 100644 index 0000000..f603f52 --- /dev/null +++ b/app/controllers/nodes_controller.rb @@ -0,0 +1,33 @@ +class NodesController < ApplicationController + + def index + @rootnodes = Node.where(parent: nil) + end + def show + @node = Node.find(params[:id]) + @nodes = Node.all + end + + def new + @node = Node.new + @nodes = Node.all + end + def create + unless params[:node][:parent].to_i == 0 + @parent = Node.find(params[:node][:parent]) + @node = @parent.children.build(title: params[:node][:title], content: params[:node][:content], parent: @parent) + else + params[:node][:parent] = nil + @node = Node.new(params.require(:node).permit(:parent,:title,:content)) + end + + + @node.save + redirect_to @node + end + + private + def node_params + + end +end |
