James Le Cuirot
2005-Nov-07 06:08 UTC
wrong number of arguments (1 for 0) / composed_of / to_f
Hello. I''m using the Money class (http://rubyforge.org/projects/money) with composed_of like this... composed_of :mounted_price, :class_name => "Money", :mapping => [ "mounted_price", "cents" ] That was working fine on its own. I then wanted to add some validation. Rather than make a separate validation block just for the money field, I figured I could use the same block as the other numerical fields. Money objects can''t be compared directly against Fixnums (though I suppose that could be added) so I used to_f... validates_each :mounted_price, :edition_size, :height, :width do |model, attrib, value| model.errors.add(attrib, "should be positive") unless value.nil? || value.to_f > 0 end The money class doesn''t have a to_f method so I added one myself... class Money def to_f @cents.to_f / 100 end end But with just the addition of that to_f method, whenever record.mounted_price or record.mounted_price= gets called from Rails, it throws up ArgumentError: wrong number of arguments (1 for 0). I tried creating a record and then calling these methods manually from IRB and that worked fine. The problem only occurs in Rails. Why!? James
James Le Cuirot
2005-Nov-07 06:33 UTC
Re: wrong number of arguments (1 for 0) / composed_of / to_f
Actually it seems like simply putting... class Money end ...has the same effect. What am I doing wrong?