gpt4 book ai didi

ruby-on-rails - Best_in_place display_with 没有找到 helper

转载 作者:行者123 更新时间:2023-12-04 12:22:59 25 4
gpt4 key购买 nike

关于如何在 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。有什么想法吗?

最佳答案

我遇到了同样的问题,并使用了 zubin 完成的 best_in_place 的拉取请求中的一个小片段。

<%= in_place_edit(@term, :starts_on, display_with: lambda { |dt| ldt(dt) }, html_attrs: {datepicker: "true"}) %>



这里的 ldt 是采用日期对象并转换为我想要的格式的方法。

希望能帮助到你

关于ruby-on-rails - Best_in_place display_with 没有找到 helper ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13561533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com