0

I'm giving discounts on products based on user's point total. But I would like to encourage users to use those points within 180 days. So, only points created_at < 180.days.ago would count.

What would be a simple way to get the only punctuation from 180 days ago?

alexandrecosta
  • 3,218
  • 2
  • 16
  • 16

2 Answers2

1

It seems too late but now I'm working on similar situation and I find this example in their own documents.

https://github.com/tute/merit#other-actions-1

In your case code would be something like this.

user.score_points.where("created_at > '#{180.days.ago}'").sum(:num_points)

Apparently, #points returns mere integer (not a Point object). So if you wanted to pick and choose points with their given date, you need to use #score_points instead.

I hope this helps.

Haruhiko
  • 26
  • 2
0

I'm not familiar with Merit, so you'll have to look at what models it gives you, but you can probably do something like this in your user model:

class User < ActiveModel::Base
  def validPonts
    self.points.select{ |p| p.created_at > 180.days.ago } 
  end
end

and then you call @user.validPoints to retrieve only the points that exist from the last 180 days.

sicks
  • 757
  • 8
  • 23