当我在表单中使用 <%= 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
发布评论