How can I have ActiveRecord's pluck also return the column name for rendering in json?

前端 未结 7 879
予麋鹿
予麋鹿 2020-12-29 02:34
def jsontest
   @users = User.all.limit(10)
   render json: @users
end

yields

{
...

\"id\": 7,
\"name\": \"Sage Smith\",
\"email\"         


        
7条回答
  •  灰色年华
    2020-12-29 03:33

    Use select instead of pluck:

    def jsontest
      @users = User.select('id, name, email, created_at').limit(10)
      render json: @users
    end
    

提交回复
热议问题