首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ruby on Rails图形API省略属性

Ruby on Rails图形API省略属性
EN

Stack Overflow用户
提问于 2019-12-18 18:04:19
回答 1查看 47关注 0票数 1

我正在用RoR构建一个grape API,并试图为我的模型创建一个GET端点,但是user_id、created_at和updated_at属性从实际的JSON对象中被截断了。

这是我的终结点:

代码语言:javascript
复制
resource :pairings do
  desc 'Gets all pairings from database'
  get do
    Pairing.all
  end
end

配对模型如下所示:

代码语言:javascript
复制
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的响应中,配对结果如下所示:

代码语言:javascript
复制
{"id"=>979, "dumb_unit_id"=>"wu5qg63k6c1iz", "smart_unit_id"=>"rjnc8yg53j29c"}

没有user_id或时间戳。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-18 19:27:16

我找到问题了。我有一个自动生成的序列化程序,它只定义了:id、:dumb_unit_id和:smart_unit_id作为属性。将:user_id作为属性添加到此文件中解决了此问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59389562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档