Skip to content

Instantly share code, notes, and snippets.

@nicedawg
Created February 25, 2020 02:39
Show Gist options
  • Save nicedawg/266fab84c1ab59ff72713267d129cd7f to your computer and use it in GitHub Desktop.
Save nicedawg/266fab84c1ab59ff72713267d129cd7f to your computer and use it in GitHub Desktop.
[Beginning Rails 6] Listing 8-20. Modified app/views/articles/_form.html.erb
<%= form_with(model: article, local: true) do |form| %>
<% if article.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>
<ul>
<% article.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :title %>
<%= form.text_field :title %>
</div>
<div class="field">
<%= form.label :location %>
<%= form.text_field :location %>
</div>
<div class="field">
<%= form.collection_check_boxes(:category_ids, Category.all, :id, :name) do |b| %>
<% b.label { b.check_box + b.text } %>
<% end %>
</div>
<div class="field">
<%= form.label :excerpt %>
<%= form.text_field :excerpt %>
</div>
<div class="field">
<%= form.label :body %>
<%= form.text_area :body %>
</div>
<div class="field">
<%= form.label :published_at %>
<%= form.datetime_select :published_at %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment