[英]DataMapper NoMethodError: undefined method `encode_json' for DateTime
I'm not sure if this is a DataMapper issue or something more Rails-specific: 我不确定这是否是DataMapper的问题或其他特定于Rails的问题:
NoMethodError: undefined method `encode_json' for Sun, 28 Nov 2010 00:00:00 -0500:DateTime NoMethodError:Sun的未定义方法“ encode_json”,2010年11月28日00:00:00 -0500:DateTime
I have a model defined as follows: 我有一个定义如下的模型:
class Match
include DataMapper::Resource
storage_names[:default] = 'matches'
property :id, Serial, :field => 'matches_id', :required => true
def self.find_matches
repository.adapter.select <<-SQL
select
m.matches_id,
m.begin_date,
m.windows_time_zone,
team1_id,
team2_id,
t1.name as team1,
t2.name as team2,
m.status,
COALESCE(md.name,'') as match_day_name,
s.name as season_name,
r.name as round_name,
c.name as competition_name,
COALESCE(g.name,'') as group_name,
COALESCE(m.use_gsm,'N') as use_gsm,
COALESCE(m.team1_finalscore,0) as team1_score,
COALESCE(m.team2_finalscore,0) as team2_score
from matches m
inner join round r on (r.round_id = m.round_id)
inner join season s on (s.season_id = r.season_id)
inner join competition c on (c.competition_id =
s.competition_id)
inner join team t1 on (t1.team_id = m.team1_id)
inner join team t2 on (t2.team_id = m.team2_id)
left outer join match_day md on (m.match_day_id =
md.match_day_id)
left outer join groups g on (r.round_id = g.round_id)
where m.begin_date <= (CURDATE() + interval 1 day)
and m.begin_date >= (CURDATE() - interval 1 day)
order by m.begin_date desc
SQL
end
end
Calling Match.find_matches
from the console returns an array of structs like the following: 从控制台调用Match.find_matches
返回一个结构数组,如下所示:
#<struct matches_id=54235, begin_date=Sun, 28 Nov 2010 00:00:00 -0500,windows_time_zone="Morocco Standard Time", team1_id=937, team2_id=943,team1="Deportes Tolima", team2="La Equidad", status="N",match_day_name="Cuadrangular Semifinal Fecha 3",
season_name="Finalizacion 2010", round_name="Cuadrangular Semifinal",competition_name="Liga Postobon - Colombia", group_name="",use_gsm="N", team1_score=0, team2_score=0>
When I try Match.find_matches.to_json
, it appears that to_json
is choking on the begin_date format. 当我尝试Match.find_matches.to_json
,似乎to_json
在begin_date格式上令人窒息。 Is there anything I can do to correct this? 有什么我可以纠正的吗? I'm using MySQL 5.1 DATETIME, which usually displays as yyyy-mm-dd hh:mm:ss (at least in the MySQL client), so something is formatting that in a way that encode_json can't digest. 我正在使用MySQL 5.1 DATETIME,它通常显示为yyyy-mm-dd hh:mm:ss(至少在MySQL客户端中),因此某些格式正在格式化,从而使encode_json无法消化。
This appears to be a bug in ActiveSupport::JSON.encode. 这似乎是ActiveSupport :: JSON.encode中的错误。 The Struct type is not supported. 不支持Struct类型。 I've opened a ticket and provide a workaround. 我已经开了票并提供了解决方法。 https://rails.lighthouseapp.com/projects/8994/tickets/6077-activesupportjsonencode-fails-for-struct-types#ticket-6077-1 https://rails.lighthouseapp.com/projects/8994/tickets/6077-activesupportjsonencode-fails-for-struct-types#ticket-6077-1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.