Adding an "Edited at:"

11 views
Skip to first unread message

Johnny Stewart

unread,
May 3, 2016, 11:27:26 AM5/3/16
to rubyonra...@googlegroups.com
I'm looking to add an edited_at field on comments etc in a Rails 5 app
(only shown if it has been edited).
I know I can compare created_at and updated_at to check if the comment
has been edited but it seems like a hit on the db if there are a lot of
comments.

Should I add an edited at boolean to the table and update it after edit?
Or am I as well to just compare created_at and updated_at?

Or is there some mechanism I can use that makes more sense than either
of these?

Johnny

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
May 3, 2016, 4:28:44 PM5/3/16
to Ruby on Rails: Talk
On 3 May 2016 at 16:26, Johnny Stewart <li...@ruby-forum.com> wrote:
> I'm looking to add an edited_at field on comments etc in a Rails 5 app
> (only shown if it has been edited).
> I know I can compare created_at and updated_at to check if the comment
> has been edited but it seems like a hit on the db if there are a lot of
> comments.
>
> Should I add an edited at boolean to the table and update it after edit?
> Or am I as well to just compare created_at and updated_at?

Don't worry about the hit on the database, bottlenecks are almost
never in the areas you expect when coding. Code it up in the simplest
way possible and worry about efficiency if it actually becomes an
issue. In any case the difference between testing a boolean and
comparing two dates is not likely to be significant.

Colin

Johnny Stewart

unread,
May 4, 2016, 6:58:08 AM5/4/16
to rubyonra...@googlegroups.com
Thanks Colin,

solid advice, I'll just use the comparison and take it from there...
Reply all
Reply to author
Forward
0 new messages