When to use helper methods and private methods in Rails? -


i have been hearing controller should concise possible. so, try keep of processing work in helper corresponding controller. but, little confused regarding whether should instead use private controller methods or helper methods.

i using helper methods processing , returning values. have no other usage now. not called views.

that's bad idea in general. helper methods shouldn't used except specific convert-something-into-string stuff (basically, should used only in views).

for else, should use service objects or similar, basically, poro (plain old ruby objects)

in controllers want handle authentication , render right thing, don't want deal else otherwise become complex.

you might want check these books improve knowledge topic:

  • growing rails applications book on how avoid putting code in wrong places , how keep codebase maintenable on long term
  • poodr ruby guide on how write object-oriented code, it's must any developer , understand why using helper it's bad idea

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -