Ad

Why Aren't Rails Helpers More Object-oriented?

- 1 answer

For example, why are the date helpers written like this:

time_ago_in_words(@from_time)

Instead of like this:

@from_time.time_ago_in_words

Is this a clear design error / inconsistency? Or is there some reason for this?

Ad

Answer

Great question!

Most of the helpers are for selecting dates / times.

http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html

I'm guessing whoever wrote it wanted a couple of util methods and so added time_ago_in_words and distance_of_time_in_words to their helper with the selects.

As time_ago_in_words and distance_of_time_in_words are presentaton focused (i.e. you may want to localize it) the developer maybe felt that the helper isn't a bad place for them.

Ad
source: stackoverflow.com
Ad