LoginSignup
1
0

More than 5 years have passed since last update.

RailsでModelではなくシンボルのキーを持つHashの配列を取得する

Last updated at Posted at 2017-05-09

pluckだと配列の配列が返ってくるのと、as_jsonだとHashのキーがシンボルではなく文字列なのを対策。

require 'lambda_driver'
posts = Post.select(:id, :title).map(&:as_json >> :symbolize_keys)
1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0