Skip to main content


General • Asked by Métouolé Mwinbé Yves Ghislain SOMDA

Hello everyone,
I am building a web app in rails to manage quality indicators of a financial institution. My apps use many complexe Queries. Unfortunately I am not very strong in rails so for my query I use simple sql but my problems is that I don't know where is the best place to write my functions that must execute a specifics queries when it's call. I would like to be able to call my functions form my views so where I must write my function to get the job done?

Actually I wrote it in my controller but my countroller is becoming too long due to the number of functions so any advices are welcome

Best regards.

This is where a service object comes into play. This is a so called “Plain Old Ruby Object (PORO)” where you can put in specific code for one "job". You can then call this object from anywhere within your app (controller, other service object, etc.).
For me to good wrap my head around I searched from some howto's, read them, noted the best practices around them (eg. only one public method) and applied it to my own app.

Not sure if there is an episode about service objects on GoRails.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.