From 6d9f4918f11d823fd806a7b35e8e6f23b66482bf Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Thu, 4 Jan 2024 23:11:33 +0100 Subject: [PATCH] Change 'Add unit' link to turbo_stream --- app/views/units/index.html.erb | 4 ++-- app/views/units/new.html.erb | 12 ------------ app/views/units/new.turbo_stream.erb | 8 ++++++++ config/locales/en.yml | 1 + 4 files changed, 11 insertions(+), 14 deletions(-) delete mode 100644 app/views/units/new.html.erb create mode 100644 app/views/units/new.turbo_stream.erb diff --git a/app/views/units/index.html.erb b/app/views/units/index.html.erb index 2f6b24d..a43e5ad 100644 --- a/app/views/units/index.html.erb +++ b/app/views/units/index.html.erb @@ -1,8 +1,8 @@
<% if current_user.at_least(:active) %> - <%= turbo_frame_tag target: dom_id(Unit.new) do %> + <%= turbo_frame_tag do %> <%= image_link_to t('.add_unit'), 'plus-outline', new_unit_path, id: :add_unit, - onclick: 'this.style.visibility = "hidden";' %> + onclick: 'this.style.visibility = "hidden";', data: {turbo_stream: true} %> <% end %> <% end %>
diff --git a/app/views/units/new.html.erb b/app/views/units/new.html.erb deleted file mode 100644 index bb80df3..0000000 --- a/app/views/units/new.html.erb +++ /dev/null @@ -1,12 +0,0 @@ - -<%= turbo_frame_tag @unit do %> - <%= turbo_stream.update @unit do %> - <%= render partial: 'form', locals: {unit: @unit} %> - <% end %> - - <%= turbo_stream.update :unit_form_frame do %> - <%= form_with model: @unit, html: {id: :unit_form} do %> - <% end %> - <% end %> -<% end %> diff --git a/app/views/units/new.turbo_stream.erb b/app/views/units/new.turbo_stream.erb new file mode 100644 index 0000000..9b5cb5b --- /dev/null +++ b/app/views/units/new.turbo_stream.erb @@ -0,0 +1,8 @@ +<%= turbo_stream.update @unit do %> + <%= render partial: 'form', locals: {unit: @unit} %> +<% end %> + +<%= turbo_stream.update :unit_form_frame do %> + <%= form_with model: @unit, html: {id: :unit_form} do %> + <% end %> +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 1814cfb..a167d62 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -58,6 +58,7 @@ en: actions: Actions add: Add back: Back + cancel: Cancel or: or register: Register sign_in: Sign in