Reputation: 55
I'm using the Impressionist gem to capture article views. A user can create an article and can view these in his dashboard. What I'm looking to do is to display a graph using Chartkick showing the amount of articles created by day, comments by day and most importantly for this question, the impressions per day of the users articles (and only his), so if the user has two impressions, per article, and has two articles, it'd show 4 in the chart for that day.
In my show action I have:
@articles = current_user.articles
@comments = @articles.comments
And in my view:
<%= area_chart [
{name: "Articles", data: @articles.group_by_week(:created_at, format: "%B %d, %Y").count },
{name: "Comments", data: @comments.group_by_week(:created_at, format: "%B %d, %Y").count },
{name: "Impressions", data: @impressions.group_by_week(:created_at, format: "%B %d, %Y").count }
]%>
I've tried so many ways of doing this, collecting the ids of the impressions, but every time I do I get 'no block given'.. like so (and try not to laugh):
@article_impressions = []
@articles.each do |article|
@impression = Impression.where(impressionable_id: article.id)
if @impression.present?
@article_impressions << [@impression.ids]
end
end
I've also tried just taking the @impression into the hash but same again, 'no block given'. I'm almost 100% certain I'm doing this the wrong way and I'm being a bit of an idiot. If anyone could help, it'd be much appreciated!
Thanks.
Upvotes: 0
Views: 193