Utility Classes In Ruby on Rails

ruby, ruby-on-rails-3

Solution

To use `new`, the thing your calling it on must be a class, not a module. You're using a module. Change `module` to `class` in `lib/utilities/network_utility.rb`.

Problem

This is probably a stupid question, but I'm new to Ruby on Rails and I could use a little guidance. I want to have a helper/utility class that performs a group of network operations and returns results. Where do I put that class and how do I use it. I've created network_helper.rb in my app/modulename/helpers directory. In my controller when I try to do ``` myNetworkHelper = ModuleName::NetworkHelper.new results = myNetworkHelper.getResults ``` I get an error ``` undefined method `new' for MyModule::NetworkHelper:Module ``` I'm sure this is just a misunderstanding of how ruby on rails works. Can I get some clarification? Would it be better to make this a class instead of a module and put it in libs? And can I add subfolders in libs and have them automatically loaded?

Original source

Related problems