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

后端 未结 3 2046
醉话见心
醉话见心 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条回答
  •  旧时难觅i
    2020-12-22 11:52

    What exactly is committed? I see:

    t.text :committed

    and

    committed.map { |day| Date::DAYNAMES.index(day) }

    That doesn't really make sense, I'm not sure how that works for you. It looks like you're storing multiple day names, if that's the case you should use an array of some sort (either strings or integers). Then you can set n_days to simply committed.length.

    I would change that column to t.string :committed, array: true, default: [] or t.integer :committed, array: true, default: [].

提交回复
热议问题