Таким образом, я делаю так в моем действии контроллера:Как читать json в контроллере Rails?
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)
Любая идея?
Update: Если я использую 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