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

前端 未结 7 829
予麋鹿
予麋鹿 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
    
    0 讨论(0)
提交回复
热议问题