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 | |
| download | rails-tree-style-activerecord-d13b636bd654244f894943c2968a7386e8379605.tar.gz rails-tree-style-activerecord-d13b636bd654244f894943c2968a7386e8379605.zip | |
initial
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/config/manifest.js | 2 | ||||
| -rw-r--r-- | app/assets/images/.keep | 0 | ||||
| -rw-r--r-- | app/assets/stylesheets/application.css | 15 | ||||
| -rw-r--r-- | app/assets/stylesheets/nodes.scss | 3 | ||||
| -rw-r--r-- | app/assets/stylesheets/style.css | 4 | ||||
| -rw-r--r-- | app/controllers/application_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/concerns/.keep | 0 | ||||
| -rw-r--r-- | app/controllers/nodes_controller.rb | 33 | ||||
| -rw-r--r-- | app/helpers/application_helper.rb | 2 | ||||
| -rw-r--r-- | app/helpers/nodes_helper.rb | 2 | ||||
| -rw-r--r-- | app/javascript/packs/application.js | 14 | ||||
| -rw-r--r-- | app/jobs/application_job.rb | 7 | ||||
| -rw-r--r-- | app/models/application_record.rb | 3 | ||||
| -rw-r--r-- | app/models/concerns/.keep | 0 | ||||
| -rw-r--r-- | app/models/node.rb | 5 | ||||
| -rw-r--r-- | app/views/layouts/application.html.erb | 15 | ||||
| -rw-r--r-- | app/views/nodes/index.html.erb | 15 | ||||
| -rw-r--r-- | app/views/nodes/new.html.erb | 18 | ||||
| -rw-r--r-- | app/views/nodes/show.html.erb | 9 |
19 files changed, 149 insertions, 0 deletions
diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..5918193 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,2 @@ +//= link_tree ../images +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/images/.keep diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..d05ea0f --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/app/assets/stylesheets/nodes.scss b/app/assets/stylesheets/nodes.scss new file mode 100644 index 0000000..bf9fafa --- /dev/null +++ b/app/assets/stylesheets/nodes.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Nodes controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/assets/stylesheets/style.css b/app/assets/stylesheets/style.css new file mode 100644 index 0000000..d779fce --- /dev/null +++ b/app/assets/stylesheets/style.css @@ -0,0 +1,4 @@ +body { + background-color: black; + color: white; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..09705d1 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/controllers/concerns/.keep 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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/helpers/nodes_helper.rb b/app/helpers/nodes_helper.rb new file mode 100644 index 0000000..673b561 --- /dev/null +++ b/app/helpers/nodes_helper.rb @@ -0,0 +1,2 @@ +module NodesHelper +end diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js new file mode 100644 index 0000000..fb5e6ca --- /dev/null +++ b/app/javascript/packs/application.js @@ -0,0 +1,14 @@ +// This file is automatically compiled by Webpack, along with any other files +// present in this directory. You're encouraged to place your actual application logic in +// a relevant structure within app/javascript and only use these pack files to reference +// that code so it'll be compiled. + +require("@rails/ujs").start() + + +// Uncomment to copy all static images under ../images to the output folder and reference +// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) +// or the `imagePath` JavaScript helper below. +// +// const images = require.context('../images', true) +// const imagePath = (name) => images(name, true) diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000..d394c3d --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..10a4cba --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/models/concerns/.keep diff --git a/app/models/node.rb b/app/models/node.rb new file mode 100644 index 0000000..c6dab06 --- /dev/null +++ b/app/models/node.rb @@ -0,0 +1,5 @@ +class Node < ApplicationRecord + has_many :children, class_name: "Node" + belongs_to :parent, class_name: "Node", optional: true + accepts_nested_attributes_for :parent +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..fdfb342 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html> + <head> + <title>Wiki</title> + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag 'application', media: 'all' %> + <%= javascript_pack_tag 'application' %> + </head> + + <body> + <%= yield %> + </body> +</html> diff --git a/app/views/nodes/index.html.erb b/app/views/nodes/index.html.erb new file mode 100644 index 0000000..2a14880 --- /dev/null +++ b/app/views/nodes/index.html.erb @@ -0,0 +1,15 @@ +<h1> suh </h1> + +<% @rootnodes.each do |rootnode| %> + <tr> + <td>PARENT: <%= rootnode.title %></td> + </tr><br> + <em> + <% rootnode.children.each do |node| %> + <tr> + <td>CHILD: <%= node[:title] %></td> + </tr><br> + <% end %> + </em> +<% end %> + diff --git a/app/views/nodes/new.html.erb b/app/views/nodes/new.html.erb new file mode 100644 index 0000000..ee0adb6 --- /dev/null +++ b/app/views/nodes/new.html.erb @@ -0,0 +1,18 @@ +<h1>new wiki page</h1> +<%= form_with scope: :node, url: nodes_path, local: true do |form| %> + <p> + <%= form.label :title %><br> + <%= form.text_field :title %> + </p> + + <p> + <%= form.label :content %><br> + <%= form.text_area :content %> + </p> + + <%= form.collection_select :parent, @nodes, :id, :title, include_blank: true %> + + <p> + <%= form.submit %> + </p> +<% end %> diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb new file mode 100644 index 0000000..c933d1e --- /dev/null +++ b/app/views/nodes/show.html.erb @@ -0,0 +1,9 @@ +<p> +<strong>Title:</strong> +<%= @node.title %> +</p> + +<p> +<strong>Content:</strong> +<%= @node.content %> +</p> |
