Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why aren't rails helpers more object-oriented?

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?

like image 327
Tom Lehman Avatar asked Mar 01 '23 20:03

Tom Lehman


1 Answers

Helpers are methods on the view object, rather than on the object they're displaying. This makes sense in an OO sense because the view is displaying the data in a particular format, so it's in charge of converting the models to that format.

like image 107
Sarah Mei Avatar answered Mar 11 '23 22:03

Sarah Mei