private 'new' method???

Hi guys,

My application suddenly started to give this message.

NoMethodError: private method `new’ called for Post.class

my post class has:

class Post < ActiveRecord::Base

belongs_to :user


How could I fix this problem?

I’m using rails 3.1.3

even if I tried to write in console this problem still happens.

The funniest thing is because this error only occurs on Post class… ;/


That’s the exception Rails console gave me:

1.9.2p290 :035 > post =
NoMethodError: private method `new’ called for Post:Class

from /home/bruno/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.3/lib/action_mailer/base.rb:455:in


from (irb):35

from /home/bruno/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in


from /home/bruno/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `


from /home/bruno/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (r


from script/rails:6:in `require’

from script/rails:6:in `’

The problem is probably somewhere in the "..." part! Sounds to me
like you decided to add a private method, above initialize, and forgot
to go back to public. That's why I usually leave the private stuff
for last. (That, and the public stuff is more important when
someone's reading the code.)

Or are there no private items in there? Are you *sure*? Use your
text editor to search for the word private. Then do protected too,
just in case.

Is there some chance something is monkeypatching your Post class and
replacing "new" with a private version?


There isn’t any private or protected modifier in my class. How can I know if something is monkeypatching my class?
thx for reply :smiley:

I find the bug!! :smiley:
This bug happens because I forgot to Add _mailer suffix to my post mailer class …

was that Post actually actionmailer class?

saw ur exception coming from action mailer ?

i cannot check now, only hv my mobile with me.

It is a Model class and a Mailer class.

But when I created my Post Mailer class I put the same name (I completely forgot to add _mailer suffix) :stuck_out_tongue:
My Model class = post.rb

My Mailer class = post.rb

That’s why this weird error was thrown. Mailer class in fact doesn’t have constructor(am I right?)

now everything is ok…

thx for your reply