Skip to content

Instantly share code, notes, and snippets.

@archonic
archonic / _index_item.haml
Last active March 23, 2021 21:07
Rails generic edit-in-place feature using Stimulus.
.row.no-gutters.attachment_item.my-3{ class: "resource_#{resource.id}", data: { controller: "edit-in-place", "edit-in-place-update-url": resource_path(resource.id), "edit-in-place-resource": "resource" } }
.col
%input{ type: :hidden, name: "attachment_detail[attachment_id]", value: file.id }
%h6
%span{ data: { target: "edit-in-place.input", fieldtype: "text", attr: "name", value: resource.name } }
%p
%span{ data: { target: "edit-in-place.input", fieldtype: "textarea", attr: "description", value: resource.description } }
.col-auto.pull-right
.btn-group{ role: "group" }
%button.btn.btn-sm{ type: "button", data: { action: "edit-in-place#editMode", target: "edit-in-place.editBtn" } }