Skip to content

Commit

Permalink
[#493][CRUD] Add the form view templates to the generator (#506)
Browse files Browse the repository at this point in the history
* [#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 <[email protected]>
  • Loading branch information
khangbui22 and malparty authored Apr 9, 2024
1 parent 688614e commit a63ef25
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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'
10 changes: 10 additions & 0 deletions .template/addons/crud/lib/templates/slim/scaffold/new.html.slim.tt
Original file line number Diff line number Diff line change
@@ -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) %>

0 comments on commit a63ef25

Please sign in to comment.