I have a ‘Cost’ model in rails. Something like the following:
class Cost < ActiveRecord::Base
belongs_to :cost_type
has_many :cost_distributions
attr_accessor :epp
def initialize()
end
However, in my tests, when I try to create new instance with the empty constructor
cost = Cost.new
I get an error: wrong number of arguments (0 for 1). Why is it ignoring my empty constructor?
You need to allow ActiveRecord to do its own initialization since you are essentially overriding the behavior. Just change your
initializeto this:However, if you don’t supply a constructor at all, Rails lets you create the model without parameters:
So is your empty
initializemethod doing anything else? If not, its not even needed.