2010-11-27 4 views
0

ため、これはDataMapperの問題以上の何かがある場合のRails固有:DataMapperのNoMethodError:未定義のメソッド `encode_json '私はよく分からないのDateTime

NoMethodError:未定義のメソッド` encode_json' 日のために、2010年11月28日00: 0:00 -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形式で窒息しているようです。これを修正するために私ができることはありますか?私はMySQL 5.1 DATETIMEを使用しています。これは通常、少なくともyyyy-mm-dd hh:mm:ss(少なくともMySQLクライアントでは)と表示されるため、 encode_jsonで消化できないものがあります。

+1

"Match.find.matches.begin_date.class"とは何レポートしますか? – aceofspades

+0

DateTimeを報告します。私は根本的な原因と思われるものを見つけました。ActiveSupport:JSON.encodeは構造体をサポートしていません。 –

+0

私はruby 1.8.7を実行しており、その問題はありません。 'Struct.new(:d).new(DateTime.parse(Time.now.to_s(:db)))[0] .to_json' – aceofspades

答えて

関連する問題