Tuesday, July 12, 2011

[Rails] mixins with an AR class not working, why?

Hi all,

I have two modules with validations in them. For example,

module FinancialData
def self.included(base)
base.validates_numericality_of :gross_income
end
end

I mix in modules like FinancialData to AR classes, and it works fine.
(When I test FinancialData behavior I do it in a tableless AR testing
module -- then, in actual the mixing-in AR classes, I just test they
include the module.)

I want to mix modules like Financial above with one another. For
example,

module Use
include FinancialData

def self.included(base)
base.validates_numericality_of :monthly_auto_production
end
end

Unfortunately, when I attempt this and then include the most dependent
module (like Use, from above) in a tableless AR class to test the Use
module, I fail with the following message (first lines only):

/stuff/lib/financial_details.rb:14:in `included': undefined
method `validates_numericality_of' for Use:Module (NoMethodError)
from /stuff/lib/use.rb:25:in `include'
from /stuff/lib/use.rb:25
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/
active_support/dependencies.rb:239:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/
active_support/dependencies.rb:239:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/
active_support/dependencies.rb:227:in `load_dependency'
...

Any suggestions as to what to add and/orhow to arrange dependent
modules to allow AR classes to use them?

Thanks,

Lille

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate