Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 查询记录的数组值_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 4 查询记录的数组值

Ruby on rails 4 查询记录的数组值,ruby-on-rails-4,Ruby On Rails 4,我有一个记录,其中一个值存储为这样的数组 #<Health id: 12, district: 43, county: 89, sub_county: 480, name_of_institution: "May Medical Center", money_received: #<BigDecimal:b6ca9318,'0.6E6',9(18)>, date_received: "2013-10-23", use_of_money: "Money used o constr

我有一个记录,其中一个值存储为这样的数组

#<Health id: 12, district: 43, county: 89, sub_county: 480, name_of_institution: "May Medical Center", money_received: #<BigDecimal:b6ca9318,'0.6E6',9(18)>, date_received: "2013-10-23", use_of_money: "Money used o construct operation theater.", grade_of_health_center: 4, opening_time: "2000-01-01 07:00:00", closing_time: "2000-01-01 18:30:00", **service_offered: ["2", "3", "4", ""]**, other_service_offered: "HIV treatement", male_patients: 54, female_patients: 78, brick_and_wattle: 9, mad_and_wattle: 2, other_structures: 9, source_of_power: [""], other_source_of_power: "Generator", toilet_facilities: true, alternative_disposal: "", separate_toilets: true, running_water: true, alternative_water: "", state_of_water: "Functional", duration_non_functional: "", placenta_pit: true, placental_disposal: "", waste_pit: true, waste_disposal: "", storage_expired_drugs: false, expired_drugs_storage: "They are burnt to ash", pregnant_mother: 15, number_of_beds: 5, delivery_beds: 1, ambulance: true, status_of_ambulance: "Functional", keep_records: true, number_of_staff: 14, medical_staff: 6, resident_medical_staff: 3, created_at: "2014-10-23 17:00:48", updated_at: "2014-10-23 21:23:36"> 

我想检索具有包含值2的服务提供数组的记录

请澄清一件事**您想检索具有包含值2的服务提供数组的记录**或**您想在健康记录列表中的“服务提供”字段中搜索值2。wheregrade\u of_Health\u center='2'此命令**@anusha我想检索包含值2try this:count=0 Health.wheregrade\u of_Health\u center='4'的服务提供数组的记录。每个记录都做| Health | if Health.service\u提供。include?'2'count=count+1 end end end end尝试一下,大部分情况下它会工作:Health.whererray\u to\u stringticket\u代码像?,%2%请让我知道它是否有效not@anusha我尝试了Health.wheregrade\u of_Health\u center='1'和数组\u to\u stringservice\u提供的类似?,%1%。包括提供的\u服务:1.count,它不起作用
Health.where("grade_of_health_center = '2'").includes(service_offered: "4").count