From e597ab12c1092bea3f84023a549e9c467927f8be Mon Sep 17 00:00:00 2001 From: Vladislav Morgunov <87144955+Zoncovsky@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:04:44 +0300 Subject: [PATCH] update post form, add turbo --- app/views/main/posts/_form.html.erb | 19 ++++++++++--------- app/views/main/posts/index.html.erb | 8 ++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/views/main/posts/_form.html.erb b/app/views/main/posts/_form.html.erb index 88e06c5..0b66b7a 100644 --- a/app/views/main/posts/_form.html.erb +++ b/app/views/main/posts/_form.html.erb @@ -9,15 +9,15 @@ <% end %> -<%= form_with(model: [:main, post], class: 'contents') do |f| %> -
-
-
-
+<%= turbo_frame_tag post do %> + <%= form_with(model: [:main, post], class: 'contents') do |f| %> +
+
+
<%= f.label :note, class: 'block mb-2 text-sm font-medium text-gray-900 dark:text-white' %> <%= f.text_area :note, class: 'bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500' %>
-
+
<% if @post.persisted? && @post.images.any? %> <% @post.images.each do |image| %> <%= image_tag image, class: 'w-20 h-20 object-cover rounded-md mt-1' %> @@ -26,9 +26,10 @@ <%= f.label :images, class: 'block mb-2 text-sm font-medium text-gray-900 dark:text-white' %> <%= f.file_field :images, class: 'block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-100 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400' %>
+
+ <%= f.submit class: 'inline-flex items-center px-5 py-2.5 mt-4 sm:mt-6 text-sm font-medium text-center text-white bg-primary-700 rounded-lg focus:ring-4 focus:ring-primary-200 dark:focus:ring-primary-900 hover:bg-primary-800' %> +
- <%= f.submit class: 'inline-flex items-center px-5 py-2.5 mt-4 sm:mt-6 text-sm font-medium text-center text-white bg-primary-700 rounded-lg focus:ring-4 focus:ring-primary-200 dark:focus:ring-primary-900 hover:bg-primary-800' %> - <%= link_to 'Back', main_posts_path, class: 'inline-flex items-center px-5 py-2.5 mt-4 sm:mt-6 text-sm font-medium text-center text-white bg-primary-700 rounded-lg focus:ring-4 focus:ring-primary-200 dark:focus:ring-primary-900 hover:bg-primary-800' %>
-
+ <% end %> <% end %> diff --git a/app/views/main/posts/index.html.erb b/app/views/main/posts/index.html.erb index 0c78ac3..2deb7a5 100644 --- a/app/views/main/posts/index.html.erb +++ b/app/views/main/posts/index.html.erb @@ -1,7 +1,11 @@
-
- <%= link_to 'New post', new_main_post_path, class: 'rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium' %> +
+ <%= link_to 'New Post', new_main_post_path, class: 'rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium', + data: {turbo_frame: dom_id(Post.new)} %> +
+
+ <%= turbo_frame_tag Post.new %>