I want to add some behaviour to ActiveRecord::Base, so I did this:
Added ActiveRecordExtensions.rb in lib directory
Added the following code to this file
module ActiveRecordExtended
class ActiveRecord::Base
def date_formatter_for(field_name)
module_eval(
“def solicitation_date_formatted \n” +
…
end
end
Added the following line to environment.rb
require ‘ActiveRecordExtensions’
In every model that I want to use the extension I add the following
line
include ActiveRecordExtended
It works well, I have all the functions available in my model. But,
validations just stop working. all validates_presence_of just don’t
work. Anybody knows what could be this?
def date_formatter_for(field_name)
4) In every model that I want to use the extension I add the following line
include ActiveRecordExtended
It works well, I have all the functions available in my model. But,
validations just stop working. all validates_presence_of just don’t
work. Anybody knows what could be this?
Ricardo,
It really depends what your code is in your module. Could you post
that to the list? Also, ActiveRecord::Extensions is already an existing
plugin, which adds plugin architecture to ActiveRecord. You may not want
to use that name (or maybe you do),
Zach
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
It really depends what your code is in your module. Could you post
that to the list? Also, ActiveRecord::Extensions is already an existing
plugin, which adds plugin architecture to ActiveRecord. You may not want
to use that name (or maybe you do),
Zach
Hello,
I guess I found a solution. My code now is like this: