我的Reminders
模型(date
和mail_date
)中有两列,其列类型为datetime
,您可以在schema.rb
中看到:
create_table "reminders", force: :cascade do |t|
t.string "name"
t.datetime "date"
t.boolean "reminder", default: false
t.string "repeating"
t.boolean "approved"
t.boolean "gift", default: false
t.boolean "gift_help", default: false
t.string "occasion_type", default: "Other"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "slug"
t.datetime "mail_date"
end
但是,在我的console
中,它们仅显示为日期:
[33] pry(main)> Reminder.where(name: "Mentor Call")
Reminder Load (0.4ms) SELECT "reminders".* FROM "reminders" WHERE "reminders"."name" = ? [["name", "Mentor Call"]]
=> [#<Reminder:0x007fe32b13f090
id: 8,
name: "Mentor Call",
date: Thu, 27 Oct 2016,
reminder: true,
repeating: "Weekly",
approved: nil,
gift: false,
gift_help: false,
occasion_type: "Other",
user_id: 1,
created_at: Thu, 13 Oct 2016 01:59:57 UTC +00:00,
updated_at: Fri, 21 Oct 2016 23:47:16 UTC +00:00,
slug: "mentor-call",
mail_date: Thu, 27 Oct 2016>]
我知道datetime
数据正在保存,因为它显示在我的视图页面上,这里......
October 27, 2016 07:00 Mentor Call ... 2016-10-27 07:00:00 UTC
...是从这个erb生成的:
<% @reminders.each do |o| %>
<tr>
<td>
<%= o.date.try(:to_formatted_s, :long) %>
</td>
<td>
<%= link_to reminder_path(o), style: "color: black" do %>
<strong><%= o.name %></strong>
<% end %>
...
<td>
<% if o.reminder %>
<%= o.mail_date.try(:to_formatted_s, "%m/%d/%Y") %>
<% else %>
None, you're on your own.
<% end %>
</td>
</tr>
我正在尝试创建mailer
,mail_date
发送datetime
,但由于此date
vs {{1}}问题,我遇到了麻烦(我认为)。谁能让我理顺?
答案 0 :(得分:1)
我怀疑date
列的名称与Rails&#39;或者Ruby的reserved words。将date
列的名称更改为其他内容,例如remind_at
,这应该可以解决问题:
create_table "reminders", force: :cascade do |t|
t.string "name"
t.datetime "remind_at"
t.boolean "reminder", default: false
# ...
end