2010-11-27 1 views
0

이는 DataMapper 문제 이상의 무언가가있는 경우 레일 별 :DataMapper NoMethodError : 정의되지 않은 메서드`encode_json '나는 확실하지 않다 날짜 시간

NoMethodError : 정의되지 않은 메서드`encode_json'일에 대한 28 년 11 월 2010 년 00 : 0시 -0500 다음과 같이 날짜 시간

나는 모델 정의 : 콘솔에서 Match.find_matches를 호출

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 

는 다음과 같은 구조체의 배열을 반환합니다

#<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> 

Match.find_matches.to_json을 시도하면 to_json이 begin_date 형식으로 질식하는 것으로 보입니다. 이 문제를 해결하기 위해 할 수있는 일이 있습니까? 나는 일반적으로 yyyy-mm-dd hh : mm : ss (적어도 MySQL 클라이언트에서는)로 표시되는 MySQL 5.1 DATETIME을 사용하고 있으므로 어떤 것이 encode_json이 소화 할 수없는 방식으로 서식을 지정하고 있습니다.

+1

"Match.find.matches.begin_date.class"는 무엇을보고합니까? – aceofspades

+0

DateTime을보고합니다. 근본 원인이라고 생각되는 것을 발견했습니다. ActiveSupport : JSON.encode는 구조체를 지원하지 않습니다. –

+0

루비 1.8.7을 실행 중이며 그 문제가 없습니다. 'Struct.new (: d) .new (DateTime.parse (Time.now.to_s (: db))) [0] .to_json' – aceofspades

답변