Datetime属性未保存到数据库

时间:2016-09-28 21:49:35

标签: ruby-on-rails ruby datetime datetime-format

我有一个具有日期时间属性的模型" date"在一个名为" show。"但是,当我尝试在表单中保存日期值时,无论我输入的值是否为nil。我注意到这也是" created_at"和" updated_at"评价。

我可以保存' date'在rails控制台......

有没有人知道为什么会这样?请参阅下面的我的控制器和表格。

new.html.erb

puts.foreachRDD(r -> {
        List<String> l = r.flatMap(t -> {
                    Collection<List<Cell>> collection = t._2().getFamilyCellMap().values();
            return collection.stream()
                    .flatMap(Collection::stream)
                    .map(CellUtil::cloneValue))
                    .collect(Collectors.toList());
                }).collect();

        //Mapping for testing
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, Object> map1 = objectMapper.readValue(l.get(1), new TypeReference<Map<String, Object>>(){});
        Map<String, Object> map2 = objectMapper.readValue(l.get(2), new TypeReference<Map<String, Object>>(){});

        System.out.println(map1);
        Assert.assertEquals(map1.get("attribute1").toString(), expected1);
        //etc
        System.out.println(map2);
        Assert.assertEquals(map2.get("attribute2").toString(), expected2);
        //etc
    }
    return null;
});

shows_controller.rb

Add a show

<%= form_for @show do |f| %>
  <%= f.text_field :name, placeholder: "name", onclick: "this.placeholder=''", onblur: "this.placeholder='name'" %>
  <%= f.datetime_field :date %>
  <%= f.text_field :location, placeholder: "location", onclick: "this.placeholder=''", onblur: "this.placeholder='location'" %>
  <%= f.file_field :flyer, placeholder: "flyer", onclick: "this.placeholder=''", onblur: "this.placeholder='flyer'" %>
  <%= f.text_field :description, placeholder: "description", onclick: "this.placeholder=''", onblur: "this.placeholder='description'" %>
  <%= f.submit "Submit", class: 'btn' %>
<% end %>

注意:我尝试使用&#34; datetime_select&#34;同样。

0 个答案:

没有答案