Rails では、同じコードを使用していても、コンソールのタイムスタンプが実際の html ビューと異なって見えることがわかりました。私が本当に愚かなことをしていない限り:
>> article = News.first
=> #<News id: 1, title: "Testing", body: "yadda yadda", role_id: 1, created_at: "2009-04-12 05:33:07", updated_at: "2009-04-12 05:33:07">
>> article.created_at
=> Sun, 12 Apr 2009 05:33:07 UTC +00:00
>> article.created_at.to_date
=> Sun, 12 Apr 2009
そしてビューで:
<% for article in @news %>
<% @current_date = article.created_at.to_date %>
<% if @current_date != @date %>
<%= @current_date %>
<% @date = @current_date %>
<% end %>
出力は次のようになります。
2009-04-14
フォーマットが異なるのはなぜですか?