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!
Module? it should bemodule