2012-03-06 3 views
1

だから、私は私のコントローラのアクションでそのようにやっている:Rails Controllerでjsonを読むには?

{"createdAt":"Mar 6, 2012 6:12:54 PM","id":177139718620856322,"text":"@rgjunio where?","source":"web","isTruncated":false,"inReplyToStatusId":177139644012572673, ... 

しかし、私はそれにアクセスしよう:

json_document = JSON(params) (json gem) 

私はそれは私にそのようなJSONを与えjson_document印刷する場合

tweet = Complaint.find_by_twitter_status json_document["inReplyToStatusId"] 

私は次のエラーを取得する:

can't convert ActiveSupport::HashWithIndifferentAccess into String 

だから私は、シンボルを使用して別の方法を試してみました:

tweet = Complaint.find_by_twitter_status json_document[:inReplyToStatusId] 

が、それは私にエラー与える:

TypeError (can't convert Symbol into Integer) 

任意のアイデアを?

アップデート: 私はのparamsを使用する場合は、[:inReplyToStatusId] isntead私が得た次

ActiveRecord::StatementInvalid (PG::Error: ERROR: operator does not exist: character varying = bigint 
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. 
SELECT "complaints".* FROM "complaints" WHERE "complaints"."twitter_status" = 177144980450721794 LIMIT 1): 
+0

' bigint' params入力を受け入れる。 – John

答えて

1

試してください:あなたが入力し、あなたの `twitter_status`列を変更する必要が

params[:inReplyToStatusId].to_s 
+0

それだけです。それは文字列フィールドだった、私はそれが大きなintだと思うエラーメッセージ。ありがとう。 – Jirico