我需要将当前用户与我捕获的json响应绑定并存储在PostgreSql 9.4中。我正在使用Rails 4.我能够成功地将json存储在一个列中并返回' json数据类型。我已经采取措施来创建模型关联并更新模式,并且我有一个带有记录的用户模型,但user_id在持有json返回的Document记录中保持为nil。我列出了控制器,因为我几乎确信我的问题就在这里。
require 'alchemyAPI/alchemyapi'
require 'json'
class AlchemyController < ApplicationController
def index
@documents = Document.all
end
def create
alchemyapi = AlchemyAPI.new()
response = alchemyapi.combined('url', params[:q], {'extract'=>'page-image, title, author, concept' })
puts JSON.pretty_generate(response)
if
Document.create(result: response)
flash[:notice] = "Input was successfully analyzed and persisted."
redirect_to action: 'index'
else
flash[:notice] = "Input was successfully analyzed and persisted."
redirect_to action: 'index'
end
end
end
答案 0 :(得分:0)
解决方案是我添加当前用户,如if块的前两行所示。
compile 'com.google.android.gms:play-services:7.0.0'