Ruby on Rails banner

Day 11: Sorting and Other Miscellany

The rest of this series can be found here.

Unfortunately, I skipped a couple of days on this project due to project workload.

Sorting

Today, first up is sorting the index; turns out pretty easy to do; all I had to do was add .order(:completed, duedate: :asc) to the index controller.

Overdue Items

If you’re keeping track of things to do and using due dates, then it makes sense to know when something is past due. This took just a bit more work: had to check if the current date/time is greater than the due date, as well as checking to see if the item is completed (no sense being notified about past-due completed items, right?).

I did run into an issue with the conditional statement not outputting the HTML tags I wanted—it just spit out the whole string including tags onto the page. .html_safe to the rescue.

Date Formatting

The ISO 8601-style date didn’t look to great, so I added .strftime to make it look a bit better.

Next up: user authentication in preparation for a public instance.

The current code can be found here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.