Typical Usage
<%= form_with(model: post, id: "posts_form") do |form| %>
<%= form.container_for :name, class: "field" do %>
<%= form.label :name %>
<%= form.text_field :name %>
<%= form.error_for :name, class: "danger hide" %>
<% end %>
<%= form.container_for :body, class: "field" do %>
<%= form.label :body %>
<%= form.text_area :body %>
<%= form.error_for :body, class: "danger hide" %>
<% end %>
<div class="actions">
<%= form.submit %>
</div>
<% end %><%= form_with(model: post, id: "posts_form") do |form| %>
<%= form.container_for :name, class: "input-group" do %>
<%= form.label :name %>
<%= form.text_field :name, class: "form-control" %>
<%= form.error_for :name, class: "small align-bottom text-danger d-none" %>
<% end %>
<%= form.container_for :body, class: "input-group" do %>
<%= form.label :body %>
<%= form.text_area :body, class: "form-control" %>
<%= form.error_for :body, class: "small align-bottom text-danger d-none" %>
<% end %>
<div class="actions">
<%= form.submit %>
</div>
<% end %>.danger {
color: red;
}
.hide {
display: none;
}
.field.error > .hide {
display: block;
}
.field.error > input,
.field.error > textarea {
background-color: rgba(255, 239, 213, 0.7);
}.input-group.error > .d-none {
display: inline !important;
}
.input-group.error > input,
.input-group.error > textarea {
background-color: rgba(255, 239, 213, 0.7);
}Gotchas
Radio buttons and checkboxes
Last updated