From f89595aff1bfbff3d0507c7383b20934ecd6b79c Mon Sep 17 00:00:00 2001 From: f Date: Fri, 17 May 2024 17:58:44 -0300 Subject: [PATCH] feat: generar la lista con links --- app/controllers/posts_controller.rb | 8 ++++++++ app/views/posts/_new_related_post.haml | 2 ++ app/views/posts/attributes/_new_has_many.haml | 8 ++++---- config/routes.rb | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 app/views/posts/_new_related_post.haml diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index f241dfb1..aad3855d 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -32,6 +32,14 @@ class PostsController < ApplicationController render layout: false end + def new_related_post + @uuid = params.require(:value).strip + + @indexed_post = site.indexed_posts.find_by!(post_id: @uuid) + + render layout: false + end + def index authorize Post diff --git a/app/views/posts/_new_related_post.haml b/app/views/posts/_new_related_post.haml new file mode 100644 index 00000000..f3cc2a94 --- /dev/null +++ b/app/views/posts/_new_related_post.haml @@ -0,0 +1,2 @@ +.col + %p= link_to post.title, post.path diff --git a/app/views/posts/attributes/_new_has_many.haml b/app/views/posts/attributes/_new_has_many.haml index 9477998d..f8ec89d4 100644 --- a/app/views/posts/attributes/_new_has_many.haml +++ b/app/views/posts/attributes/_new_has_many.haml @@ -5,7 +5,7 @@ name = "#{base}[#{attribute}][]" form_id = "form-#{Nanoid.generate}" -%div{ data: { controller: 'modal array', 'array-original-value': metadata.value.to_json, 'array-new-array-value': site_posts_new_array_value_path(site) } } +%div{ data: { controller: 'modal array', 'array-original-value': metadata.value.to_json, 'array-new-array-value': site_posts_new_related_post_path(site) } } .form-group = hidden_field_tag name, '' = label_tag id, post_label_t(attribute, post: post) @@ -34,9 +34,9 @@ - content_for :"#{id}_body" do .form-group.mb-0{ id: "#{id}_body" } - - metadata.values.each_pair do |value, key| - .mb-2{ data: { target: 'array.item', 'searchable-value': value.remove_diacritics.downcase, value: value } } - = render 'bootstrap/custom_checkbox', name: name, id: "value-#{Nanoid.generate}", value: key, checked: metadata.value.include?(key), content: value + - metadata.values.each_pair do |value, uuid| + .mb-2{ data: { target: 'array.item', 'searchable-value': value.remove_diacritics.downcase, value: uuid } } + = render 'bootstrap/custom_checkbox', name: name, id: "value-#{Nanoid.generate}", value: uuid, checked: metadata.value.include?(uuid), content: value - content_for :"#{id}_footer" do .flex-grow-1 diff --git a/config/routes.rb b/config/routes.rb index eb20edce..be50fafd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -102,6 +102,7 @@ Rails.application.routes.draw do get :'posts/new_array', to: 'posts#new_array' get :'posts/new_array_value', to: 'posts#new_array_value' + get :'posts/new_related_post', to: 'posts#new_related_post' resources :posts do get 'p/:page', action: :index, on: :collection