Q&A
Rails 5.0.0.1にて開発しています。デザインにはbootstrapを利用しています。
form_forにてeditアクション用のフォームを表示すると、datetimeのみ元々入れている日時が表示されず、空表示になってしまいます。誤りをご指摘頂けますと助かります。
編集前の画像
編集画面(datetimeのみ空になってしまっています)
migrationファイル
ruby
1class CreateLessons < ActiveRecord::Migration[5.0] 2 def change 3 create_table :lessons do |t| 4 t.string :title, null: false 5 t.string :place, null: false 6 t.text :body, null: false 7 t.datetime :starts_at, null: false 8 t.datetime :ends_at, null: false 9 10 t.timestamps 11 end 12 end 13end
edit.html.erb
ruby
1<%= form_for @lesson do |form| %> 2<%= render "form", form: form%> 3<%= form.submit %> 4<% end%>
_form.html.erb
ruby
1<div class = "container"> 2 <div class="form-group row"> 3 <%= form.label :title, "講座名", class: "col-xs-2 col-form-label" %> 4 <div class="col-xs-10"> 5 <%= form.text_field :title, class: "form-control", type: "text", 6 placeholder: "講座名を記載", id: "example-text-input" %> 7 </div> 8 </div> 9 10 <div class="form-group row"> 11 <%= form.label :place, "場所", class: "col-xs-2 col-form-label" %> 12 <div class="col-xs-10"> 13 <%= form.text_field :place, class: "form-control", type: "text", 14 placeholder: "場所を記載", id: "example-text-input"%> 15 </div> 16 </div> 17 18 <div class="form-group row"> 19 <%= form.label :body, "講義内容", class: "col-xs-2 col-form-label" %> 20 <div class="col-xs-10"> 21 <%= form.text_area :body, class: "form-control", type: "text", 22 placeholder: "講座内容を記載", id: "exampleTextarea", rows: 3 %> 23 </div> 24 </div> 25 26 <div class="form-group row"> 27 <%= form.label :starts_at, "開始日時", class: "col-xs-2 col-form-label" %> 28 <div class="col-xs-10"> 29 <%= form.text_field :starts_at, class: "form-control", type: "datetime-local", 30 id: "example-datetime-local-input"%> 31 </div> 32 </div> 33 34 <div class="form-group row"> 35 <%= form.label :ends_at, "終了日時", class: "col-xs-2 col-form-label" %> 36 <div class="col-xs-10"> 37 <%= form.text_field :ends_at, class: "form-control", type: "datetime-local", 38 id: "example-datetime-local-input"%> 39 </div> 40 </div> 41</div><!--container-->
回答1件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。