re: My first DEV PR and post! VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Interesting, this would indeed be a good improvement to be more future proof. Only thing you still would need to do is prepare the designs for the ...
 

I'd guess something like this

def self.award_x_year_badges(x)
  @n = {1=>"one", 2=>"two", 3=>"three",4=>"four", 5=>"five", 6=>"six", 7=>"seven", 8=>"eight", 9=>"nine", 10=>"ten"}
  s = x == 1 ? "" : "s"
  message = "Happy DEV birthday! Can you believe it's been #{@n[x]} year#{s} already?!"
  User.where("created_at < ? AND created_at > ?", (x).year.ago, (x * 365 + 2).days.ago).find_each do |user|
    achievement = BadgeAchievement.create(
      user_id: user.id,
      badge_id: Badge.find_by_slug("#{@n[x]}-year-club").id,
      rewarding_context_message_markdown: message,
    )
    user.save if achievement.valid?
  end
end

for x in 1..10
  self.award_x_year_badges(x)
end

Though I don't really know ruby either 😅

I'm not sure this line would work as expected

User.where("created_at < ? AND created_at > ?", (x).year.ago, (x * 365 + 2).days.ago).find_each do |user|
code of conduct - report abuse