【发布时间】:2019-12-18 10:04:18
【问题描述】:
我正在 RoR 中构建一个葡萄 API,并且我正在尝试为我的模型创建一个 GET 端点,但是 user_id、created_at 和 updated_at 属性与实际的 JSON 对象截断了。
这是我的终点:
resource :pairings do
desc 'Gets all pairings from database'
get do
Pairing.all
end
end
配对模型如下所示:
create_table "pairings", force: :cascade do |t|
t.string "dumb_unit_id", null: false
t.string "smart_unit_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "user_id", null: false
t.index ["dumb_unit_id"], name: "index_pairings_on_dumb_unit_id", unique: true
t.index ["smart_unit_id"], name: "index_pairings_on_smart_unit_id", unique: true
end
在 API 的响应中,配对最终看起来像这样:
{"id"=>979, "dumb_unit_id"=>"wu5qg63k6c1iz", "smart_unit_id"=>"rjnc8yg53j29c"}
没有 user_id 或时间戳。
【问题讨论】: