From a63ef25894e9393437a5666d51c61f5bec649a42 Mon Sep 17 00:00:00 2001 From: khangbui22 <36690900+khangbui22@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:08:29 +0700 Subject: [PATCH] [#493][CRUD] Add the form view templates to the generator (#506) * [#483] Add tests to the CRUD layout * [#483] Fix the check for slim and erb layout files * [#493] Add slim view templates for new, form, and edit * [#493] Fix view error --------- Co-authored-by: Xavier MALPARTY --- .../slim/scaffold/_form.html.slim.tt | 28 +++++++++++++++++++ .../templates/slim/scaffold/edit.html.slim.tt | 8 ++++++ .../templates/slim/scaffold/new.html.slim.tt | 10 +++++++ 3 files changed, 46 insertions(+) create mode 100644 .template/addons/crud/lib/templates/slim/scaffold/_form.html.slim.tt create mode 100644 .template/addons/crud/lib/templates/slim/scaffold/edit.html.slim.tt create mode 100644 .template/addons/crud/lib/templates/slim/scaffold/new.html.slim.tt diff --git a/.template/addons/crud/lib/templates/slim/scaffold/_form.html.slim.tt b/.template/addons/crud/lib/templates/slim/scaffold/_form.html.slim.tt new file mode 100644 index 00000000..a87356e6 --- /dev/null +++ b/.template/addons/crud/lib/templates/slim/scaffold/_form.html.slim.tt @@ -0,0 +1,28 @@ += form_with(model: <%= model_resource_name %>) do |form| + - if <%= singular_table_name %>.errors.any? + div style="color: red" + h2 = "#{pluralize(<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:" + ul + - <%= singular_table_name %>.errors.each do |error| + li = error.full_message + +<% attributes.each do |attribute| -%> + .mb-3 +<% if attribute.password_digest? -%> + = form.label :password, class: 'form-label' + = form.password_field :password, class: 'form-control' + + .mb-3 + = form.label :password_confirmation, class: 'form-label' + = form.password_field :password_confirmation, class: 'form-control' +<% elsif attribute.attachments? -%> + = form.label :<%= attribute.column_name %>, class: 'form-label' + = form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true, class: 'form-control' +<% else -%> + = form.label :<%= attribute.column_name %>, class: 'form-label' + = form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: 'form-control' +<% end -%> + +<% end -%> + div + = form.submit 'Submit', class: 'btn btn-primary' diff --git a/.template/addons/crud/lib/templates/slim/scaffold/edit.html.slim.tt b/.template/addons/crud/lib/templates/slim/scaffold/edit.html.slim.tt new file mode 100644 index 00000000..a92dbb9b --- /dev/null +++ b/.template/addons/crud/lib/templates/slim/scaffold/edit.html.slim.tt @@ -0,0 +1,8 @@ +h1 Editing <%= human_name.downcase %> + +== render "form", <%= singular_table_name %>: @<%= singular_table_name %> + +br + +div + =< link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>, class: 'btn btn-secondary' diff --git a/.template/addons/crud/lib/templates/slim/scaffold/new.html.slim.tt b/.template/addons/crud/lib/templates/slim/scaffold/new.html.slim.tt new file mode 100644 index 00000000..fb11e144 --- /dev/null +++ b/.template/addons/crud/lib/templates/slim/scaffold/new.html.slim.tt @@ -0,0 +1,10 @@ +content_for :title, "New <%= human_name.downcase %>" + +h1 New <%= human_name.downcase %> + +== render 'form', <%= singular_table_name %>: @<%= singular_table_name %> + +br + +div + = link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>