2

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.

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.

I created the /lib/modules directory and added it to my autoload paths. Then I created the file recurly_extensions.rb in that directory. The file looks like this:

Module RecurlyExtensions

    def foobar
        "This works."
    end

end

Then I added this to my user model:

include RecurlyExtensions

Then I tried to load the rails console to test if I could call .foobar on a User instance. However, the console won't load.

I get this error message:

/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)

So, it's saying I'm missing an end somewhere, but I don't see it.

Can anyone help me understand how to properly set up a module to be included in a Rails model? Thanks!

5
  • 2
    what is Module? it should be module Commented May 17, 2011 at 19:50
  • Oh for crying out loud, that's all that was wrong. Sheesh! Hey why don't you post that as an answer so I can accept it? Commented May 17, 2011 at 19:53
  • 1
    I often face this kind of stupid errors :) Commented May 17, 2011 at 20:00
  • @nash - I could, but I'd rather give credit where credit is due... Commented May 17, 2011 at 20:02
  • @apneadiving I'm glad I'm not the only one that deals with stupid errors.. Answers to these seemingly simple questions is what I spend most of my debugging looking for cause its always something simple that gets overlooked. kuddos Commented Jun 13, 2011 at 2:50

1 Answer 1

5

You should replace Module with module

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.