Get specific attributes from an ActiveRecord model

后端 未结 4 1732
你的背包
你的背包 2021-01-30 10:43

Let\'s say that I have a User model with attributes :id, :first_name, :last_name, and :email. In my application, guest users shouldn\'t see User\

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 11:15

    Try this:

    User.where(id: 5).pluck(:id, :first_name) 
    

    it returns array containing id and first_name values

提交回复
热议问题