@models.map(&:attributes)) returns a list of hashes from each column to its value in the db
How do I limit it so that only specific columns are returns (e.g. just name and id?).
Also, how do I combine multiple columns to a new key => value pair? For example, if a user has first_name and last_name, the above would return
[{"first_name" => "foo", "last_name" => "bar"}] but I want it to be [{"name" => "foo bar"}]
How do I achieve this transformation? Thanks!
For the first part (limiting the attributes in the hash):
For combining multiple attribute into a new attribute, the cleanest way is usually an accessor method:
Then build your hash manually during iteration:
If you’re using more than one attribute from the attributes hash, you can use merge: