title: Rails 3: How to add a module to a model?
body: <p>I've got a User model in my Rails 3 app which is getting huge. I want to extract a bunch of functions which are related to subscription billing and place them in a module.</p>
  
  <p>This is the first time I've attempted to write a module, and the first thing I tried was just to create a minimal module with a test method and see if it worked.</p>
  
  <p>I created the <code>/lib/modules</code> directory and added it to my autoload paths. Then I created the file <code>recurly_extensions.rb</code> in that directory. The file looks like this:</p>
  
  <pre><code>Module RecurlyExtensions
  
      def foobar
          "This works."
      end
  
  end
  </code></pre>
  
  <p>Then I added this to my user model:</p>
  
  <pre><code>include RecurlyExtensions
  </code></pre>
  
  <p>Then I tried to load the rails console to test if I could call <code>.foobar</code> on a User instance. However, the console won't load.</p>
  
  <p>I get this error message:</p>
  
  <pre><code>/Users/Andrew/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:454:in `load': /Users/Andrew/Rails/fourth_env/lib/modules/recurly_extensions.rb:7: syntax error, unexpected keyword_end, expecting $end (SyntaxError)
  </code></pre>
  
  <p>So, it's saying I'm missing an <code>end</code> somewhere, but I don't see it.</p>
  
  <p>Can anyone help me understand how to properly set up a module to be included in a Rails model? Thanks!</p>