Skip to content

Commit 47a3301

Browse files
Improve boolean fields
1 parent b128001 commit 47a3301

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/generators/tailwindcss/scaffold/templates/_form.html.erb.tt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<%%= form_with(model: <%= model_resource_name %>, class: "contents") do |form| %>
22
<%% if <%= singular_table_name %>.errors.any? %>
3-
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-md mt-3">
3+
<div id="error_explanation" class="px-3 py-2 mt-3 font-medium text-red-500 rounded-md bg-red-50">
44
<h2><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
55

6-
<ul class="list-disc ml-6">
6+
<ul class="ml-6 list-disc">
77
<%% <%= singular_table_name %>.errors.each do |error| %>
88
<li><%%= error.full_message %></li>
99
<%% end %>
@@ -12,7 +12,7 @@
1212
<%% end %>
1313

1414
<% attributes.each do |attribute| -%>
15-
<div class="my-5">
15+
<div class="my-5<%= " flex items-center gap-2" if attribute.field_type == :checkbox || attribute.field_type == :check_box %>">
1616
<% if attribute.password_digest? -%>
1717
<%%= form.label :password %>
1818
<%%= form.password_field :password, class: ["block shadow rounded-md border outline-none px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:password].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:password].any?}] %>
@@ -29,7 +29,7 @@
2929
<% if attribute.field_type == :textarea || attribute.field_type == :text_area -%>
3030
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, rows: 4, class: ["block shadow rounded-md border outline-none px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].any?}] %>
3131
<% elsif attribute.field_type == :checkbox || attribute.field_type == :check_box -%>
32-
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: ["block shadow rounded-md border outline-none mt-2 h-5 w-5", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].any?}] %>
32+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: ["block shadow rounded-md border outline-none order-first h-5 w-5", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].any?}] %>
3333
<% else -%>
3434
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: ["block shadow rounded-md border outline-none px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].any?}] %>
3535
<% end -%>

lib/generators/tailwindcss/scaffold/templates/partial.html.erb.tt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<div id="<%%= dom_id <%= singular_name %> %>">
22
<% attributes.reject(&:password_digest?).each do |attribute| -%>
33
<p class="my-5">
4-
<strong class="block font-medium mb-1"><%= attribute.human_name %>:</strong>
4+
<strong class="block mb-1 font-medium"><%= attribute.human_name %>:</strong>
55
<% if attribute.attachment? -%>
66
<%%= link_to <%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached? %>
77
<% elsif attribute.attachments? -%>
88
<%% <%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
99
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
1010
<%% end %>
11+
<% elsif attribute.type == :boolean %>
12+
<%%= <%= singular_name %>.<%= attribute.column_name %> ? "Yes" : "No" %>
1113
<% else -%>
1214
<%%= <%= singular_name %>.<%= attribute.column_name %> %>
1315
<% end -%>

0 commit comments

Comments
 (0)