简体   繁体   English

数组的未定义方法“年”

[英]Undefined method `year' for Array

I want to select date by date_select, but in database I have query: 我想通过date_select选择日期,但是在数据库中我有以下查询:

"DATE_INTEGRATION" LIKE '["2008", "8", "28"]%

I use Metasearch in my form: 我以以下形式使用元搜索:

<%= f.date_select :date_integration_sw %>

Error: 错误:

undefined method `year' for ["2008", "8", "28"]:Array

How i fix it? 我该如何解决?

I want to get LIKE '2010-08-10%' , or convert <%= f.date_select :date_integration_sw %> , to 2010-08-10 in date_select . 我想获得LIKE '2010-08-10%'或在date_select <%= f.date_select :date_integration_sw %>转换为2010-08-10

Expanding monanik's answer, to turn the array into a Date object, do this: 扩展monanik的答案,将数组转换为Date对象,请执行以下操作:

Date.parse(["2008", "8", "28"].join('-'))

This returns an object that responds to the methods year , month , and day . 这将返回一个对象,该对象响应yearmonthday

安装Array,将'Date'或'Datetime'传递给f.date_select

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM