This will be a long one, sorry about that.
I've been playing with Ruby and Rails for the last year, but only
getting a little more "serious" now. I like how one line in a model
("has_many", for example) will create several methods for you, and I
had a need to do something similar myself, so I decided to give it a
shot, looking at other people's codes. Please bear in mind I am no
expert in Ruby or Rails, but this is what I tried:
First, I include my model in ActiveRecord::Base on startup, by doing
(/config/environment.rb, last line)
Then the module itself:
# I actually have different instance method modules, this is why I
went with this way
def my_cool_method; "COOL!"; end
def my_other_cool_method; "COOLER!"; end
Finally, the actual model:
class MyModel < ActiveRecord::Base
do_my_stuff # now every MyModel instance should have my_cool_method
class MainController < ApplicationController
@mymodel = MyModel.find(:first)
render :text => @mymodel.my_cool_method
After all this, I run to http://localhost:3000/main/index
First run outputs "COOL!", as expected
A copy of MyTest::ClassMethods has been removed from the module tree
but is still active!
I'll spare you the full trace, but it begins like this:
Well, that's about it. I've googled the message, been through several
Trac tickets and forum postings, but all of them seem to be from
before rails 1.2.3 (which is the version I'm using) and related to
plugins who had controllers, and before_filters, and the such. I don't
have any of those, so this is why I'm asking here.
I'm using Rails 1.2.3 and ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-
I appreciate any help you can give me with this.