小编Vol*_*eee的帖子

RoR-Model.all,但不包含created_at和Updated_at字段

我是Ruby的新手,所以这个问题对您来说可能看起来很愚蠢,是的。但是还是...我有一个模型组,当我运行它时

class GroupsController < ApplicationController
  prepend SimpleCommand
    ...
    def index
        @group = Group.all
        render json: @group
    end
    ...
    # some other stuff
Run Code Online (Sandbox Code Playgroud)

...然后我得到一个如下数组的响应:

[
  {
    "id": 1020,
    "name": "??-16-1",
    "has_subgroups": true,
    "created_at": "2017-09-29T10:14:08.000Z",
    "updated_at": "2017-09-29T10:14:08.000Z"
  }
...
]
Run Code Online (Sandbox Code Playgroud)

但是我不想拥有最后两个字段,所以我的答案是如何在响应中摆脱“ created_at”和“ updated_at”字段?

UPD:

在原始问题中找到了一个很好的解决方案,而我不小心为此做了一个重复。继续阅读

ruby model ruby-on-rails

5
推荐指数
1
解决办法
198
查看次数

标签 统计

model ×1

ruby ×1

ruby-on-rails ×1