My ApplicationHelper
have more than 100 lines, and the Rubocop alert me that "Module has many lines". What the good practices for solve this? Divide it in another helper
? Create a lib
?

- 1,549
- 1
- 23
- 46
3 Answers
I dont know what all you have in application helper, but ideally it should go like following:
Functions that are related to rendering views should be in helper files, They typically generate HTML content. So I think methods those are generating html should go in helpers, and other methods even if they are helping view by any means, you should group them together and have a lib file.
Now about application helper, Code in the application helper is included in all the views in your application, So if the helper method is used across the app in many places, then only put them in application_helper.rb, otherwise they have to be placed in corresponding helper files.
you can also look at following link for What goes where in ROR:
Rails Model, View, Controller, and Helper: what goes where?
Hope it helps you.
-
So lib files be most appropriated for this – Luiz Carvalho Sep 21 '16 at 14:12
-
Methods not rendering views or not generating HTML content ---> move them to lib...................................and for rest of the methods if they are not generic then you can move them to respective helpers...............................and if they all are generic methods you can create another generic helper file like "app_name_application_helper.rb" and can move few methods here, and include this file in ApplicationHelper. – Tushar H Sep 22 '16 at 05:48
Typically your helper files are meant to help out in rendering your views. Only helpers which are shared across views should be in ApplicationHelper
. For example if you have helper methods for your User View, then those methods should be in UsersHelper
and not ApplicationHelper

- 16
- 1
- 2
-
My `ApplicationHelper` contains only necessaries global methods. =\ – Luiz Carvalho Sep 21 '16 at 14:13
It's tough to say without looking at the code, but I imagine there are probably some helper methods that could be reduced in size, and possibly some helper methods that are not needed throughout your whole application which could be moved to a more specific file. Also, you can move similar/related helpers into their own file, and require that within ApplicationHelper.

- 3,749
- 2
- 22
- 22
-
So, this file with similar will be another helper? or other type? – Luiz Carvalho Sep 21 '16 at 14:11
-
I'd probably add a folder under app/helpers/ where similar functionality is grouped into another helper and if the methods are needed all over the app just require that file from your base application_helper.rb – chad_ Sep 21 '16 at 14:29