Skip to content

Instantly share code, notes, and snippets.

@leopolicastro
Created May 17, 2022 22:01
Show Gist options
  • Save leopolicastro/4cf27360de7ff22d8d5017eb27c2fbc2 to your computer and use it in GitHub Desktop.
Save leopolicastro/4cf27360de7ff22d8d5017eb27c2fbc2 to your computer and use it in GitHub Desktop.
<%# _inline_edit.html.erb %>
<% frame_id = dom_id(model, "#{attribute}_turbo_frame") %>
<%= form_with model: model, class: "contents", data: { turbo_frame: frame_id } do %>
<turbo-frame id="<%= frame_id %>" class="group inline-edit flex items-center">
<%= link_to edit_polymorphic_path(model), class: "text-main mr-3" do %>
<i class="fa-solid fa-pen-to-square text-main text-xl"></i>
<% end %>
<%= yield %>
</turbo-frame>
<% end %>
# usage
<%= render "shared/inline_edit", model: birthday, attribute: :date do %>
<%= humanized_date birthday.date %>
<% end %>
<%# _inline_fields.html.erb %>
<% frame_id = dom_id(form.object, "#{attribute}_turbo_frame") %>
<turbo-frame id="<%= frame_id %>" class="contents">
<%= yield %>
<div class="flex items-center justify-between w-12 my-2 ml-3">
<%= form.button class: "inline-action" do %>
<i class="fa-solid fa-floppy-disk text-main"></i>
<% end %>
<%= link_to polymorphic_path(form.object), class: "inline-action text-red-500 inline-action" do %>
<i class="fa-solid fa-ban"></i>
<% end %>
</div>
</turbo-frame>
# usage
<%= render "shared/inline_fields", form: form, attribute: :name do %>
<%= form.text_field :name, class: "form-control" %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment