将数据从 `datetime

编程入门 行业动态 更新时间:2024-10-27 10:31:09
本文介绍了将数据从 `datetime_select` 转换为 DateTime 对象的 Rails 方法在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我在表单中使用 <%= f.datetime_select :somedate %> 时,它会生成如下 HTML:

When I use <%= f.datetime_select :somedate %> in a form, it generates HTML like:

<select id="some_date_1i" name="somedate1(1i)"> #year <select id="some_date_2i" name="somedate1(2i)"> #month <select id="some_date_3i" name="somedate1(3i)"> #day <select id="some_date_4i" name="somedate1(4i)"> #hour <select id="some_date_5i" name="somedate1(5i)"> #minute

提交该表单时,会收到 somedate1(i) 值:

When that form is submitted, the somedate1(<n>i) values are received:

{"date1(1i)"=>"2011", "date1(2i)"=>"2", "date1(3i)"=>"21", "date1(4i)"=>"19", "date1(5i)"=>"25"}

如何将其转换为 DateTime 对象?

How can I convert that into a DateTime object?

我可以编写自己的方法来执行此操作,但是由于 Rails 已经能够进行转换,我想知道是否可以调用该 Rails 方法来为我执行此操作?

I could write my own method to do this, but since Rails already is able to do the conversion, I was wondering if I could call that Rails method to do it for me?

我不知道去哪里找那个方法.

I don't know where to look for that method.

我最终是想解决如何处理日期/POST 参数中的次数?",这个问题是尝试找到其他问题的解决方案的第一步.

I'm ultimately trying to solve "How to handle date/times in POST parameters?" and this question is the first step in trying to find a solution to that other problem.

推荐答案

那个代码路径的开始,似乎就在这里:

The start of that code path, seems to be right about here:

github/rails/rails/blob/d90b4e2/activerecord/lib/active_record/base.rb#L1811

这很难找到!我希望这可以帮助您找到所需的内容

That was tricky to find! I hope this helps you find what you need

更多推荐

将数据从 `datetime

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

发布评论

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

>www.elefans.com

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