_form.html.erb
code:app/views/_form.html.erb 前半
<%= form_with(model: place, local: true) do |form| %>
<% if place.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(place.errors.count, "error") %> prohibited this place from being saved:</h2>
<ul>
<% place.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
エラーを表示するコード
code:app/views/_form.html.erb 後半
<div class="field">
<%= form.label :date %>
<%= form.date_select :date %>
</div>
<div class="field">
<%= form.label :weather %>
<%= form.text_field :weather %>
</div>
<div class="field">
<%= form.label :place %>
<%= form.text_field :place %>
</div>
<div class="field">
<%= form.label :memo %>
<%= form.text_area :memo %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
フォームのパーツを表示する部分
https://gyazo.com/24e1884c5708d01c4af9415da3450ef2
form.label :date
Date という文字列を表示。
form.date_select :date
form は formブロック内の変数。
place に関する form を記述するために使用。
ないけど、id: :title
id 属性として出力される。
この場合は id="title" になる。
<%= form.submit %>