1
所以,我做的一樣,在我的控制器操作:如何在Rails控制器中讀取json?
json_document = JSON(params) (json gem)
如果我打印json_document它給了我一個JSON這樣的:
{"createdAt":"Mar 6, 2012 6:12:54 PM","id":177139718620856322,"text":"@rgjunio where?","source":"web","isTruncated":false,"inReplyToStatusId":177139644012572673, ...
但是,當我嘗試訪問它:
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):
你需要改變你的'twitter_status'欄鍵入'bigint'接受參數輸入。 – John 2012-03-06 21:48:28