Reputation: 331
I have seen some of the gems. They used some view logic in helper file like Rails view helpers in helper file. What is the role of helper file in rails. The helper file belongs to view family ?
Upvotes: 1
Views: 159
Reputation: 3626
Helper files allow you to move code out of the view (which should look as much like a pure template as possible) and into a place which feels more code-ey. This is good because it helps separate concerns and can promote code reuse across templates.
** WARNING: OPINIONS AHEAD **
However, many people complain about the way helpers have been implemented in Rails. I've grown to see them as sub-optimal as well. Some people even complain about the whole concept of helpers.
They're implemented as modules, which causes problems (with testing for example, or inheritance.)
They can easily become a dumping ground for functionality you can't think of a place for. This is bad because it helps your application become 'calcified' - random distribution of spaghetti code eventually makes even simple changes difficult and dangerous.
It's often better to think of an appropriate object to encapsulate the behaviour and use that.
For a simple application though, helpers can be... Well, helpful.
Upvotes: 2