FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
Simplifying timestamp toggles in Rails
How-ToWeb Development

Simplifying timestamp toggles in Rails

via Dev.to WebdevRails Designer1mo ago

This article was originally published on Rails Designer's Build a SaaS Blog I often use timestamps, like completed_at as a boolean flag. It offers just a bit more (meta) data than a real boolean. But of course on the UI you want to show a checkbox that a user can toggle instead of a datetime field. I have done this often enough, that I created a simple concern that I use throughout my apps. Given above completed_at example, it gives you an API like: @resource . completed? @resource . complete! @resource . complete = So in your form, you can simply use form.check_box :completed and you're off. The concern is simple enough: # lib/boolean_attributes.rb module BooleanAttribute extend ActiveSupport :: Concern class_methods do def boolean_attribute ( * fields ) fields . each do | field | column = :" #{ field } _at" define_method ( field ) { public_send ( column ). present? } define_method ( " #{ field } ?" ) { public_send ( column ). present? } define_method ( " #{ field } =" ) do | value |

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
22 views

Related Articles

How-To

Learn Something Old Every Day, Part XVIII: How Does FPU Detection Work?

Lobsters • 3d ago

“Learn to Code” Is Dead… Learn to Think Instead
How-To

“Learn to Code” Is Dead… Learn to Think Instead

Medium Programming • 3d ago

How-To

How One File Makes Claude Code Actually Follow Your Instructions

Medium Programming • 3d ago

LeetCode Solution: 121. Best Time to Buy and Sell Stock
How-To

LeetCode Solution: 121. Best Time to Buy and Sell Stock

Dev.to Tutorial • 3d ago

The Feature Took 2 Hours to Build — and 2 Weeks to Fix
How-To

The Feature Took 2 Hours to Build — and 2 Weeks to Fix

Medium Programming • 3d ago

Discover More Articles