表格中的日期时间列上的Strftime(Strftime on datetime column from table)

编程入门 行业动态 更新时间:2024-10-23 13:33:26
表格中的日期时间列上的Strftime(Strftime on datetime column from table)

我有一个来自表的实例变量ride ,它有一个列ride.pickup_at

如果我做<%= ride.pickup_at.class.name %>我得到

时间

所以Strftime应该可用。

现在,如果我做<%= ride.pickup_at.strftime('%x') %>我收到错误

nil的未定义方法`strftime':NilClass

我需要做些什么才能使strftime可用?

I am have a instance variable ride that comes from a table and it has a column ride.pickup_at

If I do <%= ride.pickup_at.class.name %> I get

time

So Strftime should be available.

Now, if I do <%= ride.pickup_at.strftime('%x') %> I get an error

undefined method `strftime' for nil:NilClass

What do I have to do to make strftime available?

最满意答案

你可以try使用nil判断: <%= ride.pickup_at.try(:strftime, '%x') %> 。或者我认为如果ride.pickup_at nil你应该弄清楚该做什么

you can use try to do the nil judge: <%= ride.pickup_at.try(:strftime, '%x') %> .Or I think you should figure out what to do if ride.pickup_at is nil

更多推荐

本文发布于:2023-08-06 22:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1456598.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表格   日期   时间   Strftime   column

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!