0

This is probably a really easy problem to solve, but I have a query that pulls data from two models. The only thing I want to see from this query would be the averages (numbers at the end of each string), in an array. However, the output currently looks like this:

{"[\"Orthodontist\", 2011, 4]":"545625.5","[\"Orthodontist\", 2011, 3]":"534927.0","[\"Orthodontist\", 2011, 2]":"524438.5","[\"Orthodontist\", 2011, 1]":"514155.5"}

I want the array to look like this:

[545625.5, 534927.0, 524438.5, 514155.5]

The code looks like this:

<%= Quarter.includes(:client).group('clients.specialty', 'quarters.year','quarters.quarter').limit(4)
.order('quarters.created_at DESC').average('quarters.collections').to_json %>

What should I do?

1 Answer 1

1

Before to_json add values

<%= Quarter.includes(:client).group('clients.specialty', 'quarters.year','quarters.quarter').limit(4)
.order('quarters.created_at DESC').average('quarters.collections').values.to_json %>
Sign up to request clarification or add additional context in comments.

2 Comments

Oh man, thanks! That's just what I needed. I haven't used ".values" before. So now the output is: ["545625.5","534927.0","524438.5","514155.5"] Is there any way to take away the "" marks?
@FattRyan ..your query basically returns a hash...values give the values of the hash in an array

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.