【发布时间】:2012-11-13 17:37:06
【问题描述】:
关于如何在 Best In place 中使用 display_with 选项的文档并不多,但我正在尝试让 Best_in_Place 以精简形式(mm/dd/yyyy)显示日期。 我的数据库(sqlserver)以日期时间格式存储日期,我使用此命令显示该字段:
<%= best_in_place(@production, :budget_approval_internal, type: :date, :nil => "[Not set]") %>
单击 gem 时,按预期工作,放置一个日历控件以选择日期,然后以简短形式显示它。但是当我按下刷新时,我得到的日期看起来像:
2013-12-04 00:00:00 UTC
所以我想我可以使用 :display_with 选项来使用如下所示的帮助器:
def format_date(my_date)
my_date.strftime('%m/%d/%Y')
end
我把它放在 application_helper.rb 模块中,然后尝试了这个:
<%= best_in_place(@production, :budget_approval_internal, type: :date, :display_with => :format_date, :nil => "[Not set]") %>
但我说错了:
“找不到帮助程序 format_date。有什么想法吗?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 best-in-place