How to Make :level Change Based on :committed Days?

后端 未结 3 2028
醉话见心
醉话见心 2020-12-22 11:29

I\'m creating a habit tracking app.

When a User creates a habit he will put in its :date_started and which days he is :committed to doing t

3条回答
  •  时光说笑
    2020-12-22 12:02

    I believe your only problem is that you're storing the day names in lowercase in the committed field, and then trying to match them with Date::DAYNAMES, which has them in title case. Otherwise, the logic seems sound.

    This should work:

    committed_wdays = committed.map { |day| Date::DAYNAMES.index(day.titleize) }
    n_days = ((date_started.to_date)..Date.today).count { |date| committed_wdays.include? date.wday }
    

提交回复
热议问题