Help with Transient Error involving constructor on ActiveRecord::Base

Hi,

I am encountering a strange problem where I am getting an exception in one of my controllers where the line is essentially:

@model = Model.new(params[:model])

I get the following exception:

A ArgumentError occurred in model#model_create:

  wrong number of arguments (1 for 0)
  [RAILS_ROOT]/app/controllers/model_controller.rb:80:in `initialize'

which is pretty strange because it only occurs sometimes, and I cannot reproduce it in development, just production.

I use an Apache 2.2.2 system with a pack of mongrels behind it.

ruby 1.8.4 (2005-12-24) [x86_64-linux]

These are the versions of my gems:
mongrel (0.3.13.3)
activerecord (1.14.4, 1.14.3)
rails (1.1.6, 1.1.5, 1.1.4)
actionpack (1.12.5, 1.12.4, 1.12.3)
activesupport (1.3.1)

I have tried it on my development machine (OS X) with Mongrel, but I cannot get it to reproduce. Just on my production machine :frowning:

Any ideas?

Thanks,
Curtis

Most likely you can't have a Model named Model since that's what Model
is already named: Model.

Zed,

Haha, sorry I should have been more specific. That is not the real model name. I was just making the question more generic, which inevitably caused confusion. My bad...

@widget = Widget.new(params[:widget])

I only get the exception periodically...

-Curtis

Zed Shaw wrote:

Curtis Spencer wrote:

Zed,

Haha, sorry I should have been more specific. That is not the real model
name. I was just making the question more generic, which inevitably
caused confusion. My bad...

@widget = Widget.new(params[:widget])

I only get the exception periodically...

-Curtis

After doing some more late night testing, I wanted to add a few other
things I noticed with the problem.

After a fresh restart of the mongrel processes, I cannot reproduce the
constructor problem. I did this late last night, and I thought
everything was good, but in the morning I can continue to get the
exceptions, so it is something that is occurring over a period of a few
hours (probably of little or no activity on the site)? Could it have to
do with the database?

I have ActiveRecord::Base.verification_timeout = 14400, and I don't
notice any Mysql Connection gone away errors.

A ArgumentError occurred in prime#prime_create:

   wrong number of arguments (1 for 0)
   [RAILS_ROOT]/app/controllers/prime_controller.rb:80:in `initialize'

which is pretty strange because it only occurs sometimes, and I cannot
reproduce it in development, just production.

I will repost my environment here:

I use an Apache 2.2.2 system with a pack of mongrels behind it.

ruby 1.8.4 (2005-12-24) [x86_64-linux]

These are the versions of my gems:
mongrel (0.3.13.3)
activerecord (1.14.4, 1.14.3)
rails (1.1.6, 1.1.5, 1.1.4)
actionpack (1.12.5, 1.12.4, 1.12.3)
activesupport (1.3.1)

Is there some way I can find out what could be causing it.
As for my model it is called Prime. The only other thing I can imagine
is that something in the ruby world collides with it so that it would
have a no argument constructor?

Thanks in advance for any help.

-Curtis

Try to forcefully load your models in your environment.rb or in your controller. I believe Rails will load them as needed, and
sometimes your controller code will call a model before it's been required.

Zach,

In my ApplicationController, I have a model call with all of the models
I use in my sessions, including this model.

model :prime

Does the order matter in this call because I have :prime toward the end.

Although it seems as though the model is required because ruby knows
about the symbol Prime, but it just throws the argument error on the
constructor.

-Curtis

Oh, are you using the MySQL driver that came with Rails or the compiled
gem? The driver that comes with rails has this problem when talking to
a MySQL 5.x database.