diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-16 15:12:07 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-16 15:12:07 +0200 |
| commit | b701669d0d9a5d7be01f99b8e725c05c6c5d52ce (patch) | |
| tree | 010407f079df74732cb2c6a86e49b7b72699e334 | |
| parent | c769bfb1b565cafd7a386dba5cae5b6bd4d1d38b (diff) | |
Split current_unique_name in a setter and an accessor
Also clean up some instance variable assignments on the way.
| -rw-r--r-- | app/controllers/nodes_controller.rb | 12 | ||||
| -rw-r--r-- | app/models/node.rb | 7 | ||||
| -rw-r--r-- | app/views/nodes/new.html.erb | 4 |
3 files changed, 9 insertions, 14 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index b66ea49..9834a17 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -27,12 +27,7 @@ class NodesController < ApplicationController | |||
| 27 | def new | 27 | def new |
| 28 | @node = Node.new node_params | 28 | @node = Node.new node_params |
| 29 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" | 29 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" |
| 30 | if params.has_key?(:parent_id) | 30 | @parent = Node.find(params[:parent_id]) if params.has_key?(:parent_id) |
| 31 | @parent_id = params[:parent_id] | ||
| 32 | parent = Node.find(@parent_id) | ||
| 33 | @parent_name = parent.title | ||
| 34 | @parent_unique_name = parent.current_unique_name | ||
| 35 | end | ||
| 36 | end | 31 | end |
| 37 | 32 | ||
| 38 | def create | 33 | def create |
| @@ -57,10 +52,7 @@ class NodesController < ApplicationController | |||
| 57 | redirect_to(edit_node_path(@node)) | 52 | redirect_to(edit_node_path(@node)) |
| 58 | else | 53 | else |
| 59 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" | 54 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" |
| 60 | if params[:parent_id].present? | 55 | @parent = Node.find(params[:parent_id]) if params.has_key?(:parent_id) |
| 61 | @parent_id = params[:parent_id] | ||
| 62 | @parent_name = Node.find(@parent_id).title | ||
| 63 | end | ||
| 64 | render :new | 56 | render :new |
| 65 | end | 57 | end |
| 66 | end | 58 | end |
diff --git a/app/models/node.rb b/app/models/node.rb index 6ca607d..717f5b4 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -268,9 +268,12 @@ class Node < ApplicationRecord | |||
| 268 | parent.nil? ? [slug] : parent.path_to_root.push(slug) | 268 | parent.nil? ? [slug] : parent.path_to_root.push(slug) |
| 269 | end | 269 | end |
| 270 | 270 | ||
| 271 | def computed_unique_name | ||
| 272 | path = path_to_root[1..-1].join("/") # excluding root | ||
| 273 | end | ||
| 274 | |||
| 271 | def current_unique_name | 275 | def current_unique_name |
| 272 | path = path_to_root[1..-1] # excluding root | 276 | self.unique_name = computed_unique_name |
| 273 | self.unique_name = path.join("/") | ||
| 274 | end | 277 | end |
| 275 | 278 | ||
| 276 | def update_unique_name | 279 | def update_unique_name |
diff --git a/app/views/nodes/new.html.erb b/app/views/nodes/new.html.erb index 49149d5..38eac84 100644 --- a/app/views/nodes/new.html.erb +++ b/app/views/nodes/new.html.erb | |||
| @@ -32,8 +32,8 @@ | |||
| 32 | <div id="parent_search_field" style="<%= @selected_kind == "generic" ? "" : "display: none;" %>"> | 32 | <div id="parent_search_field" style="<%= @selected_kind == "generic" ? "" : "display: none;" %>"> |
| 33 | <div class="node_description">Parent</div> | 33 | <div class="node_description">Parent</div> |
| 34 | <div class="node_content"> | 34 | <div class="node_content"> |
| 35 | <%= text_field_tag :parent_search_term, @parent_name %> | 35 | <%= text_field_tag :parent_search_term, @parent&.title %> |
| 36 | <%= hidden_field_tag :parent_id, @parent_id, data: { unique_name: @parent_unique_name } %> | 36 | <%= hidden_field_tag :parent_id, @parent&.id, data: { unique_name: @parent&.current_unique_name } %> |
| 37 | <div id="parent_search_results" class="search_results"></div> | 37 | <div id="parent_search_results" class="search_results"></div> |
| 38 | </div> | 38 | </div> |
| 39 | </div> | 39 | </div> |
