0

I have a few helpful functions I want to use in my controller but I don't know where to put them. For instance I have a method to form a JSON structure which I need to use a few times.

I would probably end up putting it in some form of utilities class which would contain a bunch of useful functions. Is this the correct way to go about it?

DWB
  • 1,544
  • 2
  • 16
  • 33
  • 1
    Opinion vary; it also depends on the amount on functions you have, \ how long they are, and where you use them ... For a small app, putting a 4 short helper function in `ApplicationController` is perfectly okay, but if you have a few (related) & longer functions, you could consider putting them in a concern... – Martin Tournoij Dec 31 '14 at 12:30
  • @Vucko definitely true, thanks for the link. I am glad I asked though, pabliiitoo's answer wasn't mentioned in the link and is more appropriate for controller specific helpers. – DWB Dec 31 '14 at 12:38

1 Answers1

1

The correct way to put helpers functions, is put them as private in the same controller or put in application controller if your helpers functions are used in most of your controllers.

EDITED

If your helpers functions have any function needed on the view, use helpers

ppascualv
  • 1,137
  • 7
  • 21