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

end

How could I fix this problem?
I’m using rails 3.1.3
even if I tried to write Post.new in console this problem still
happens.
The funniest thing is because this error only occurs on Post class… ;/
Thx


Bruno M.

That’s the exception Rails console gave me:

1.9.2p290 :035 > post = Post.new
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:inmethod_missing’
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
start' from /home/bruno/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in
start’
from
/home/bruno/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands.rb:40:in
<top (r equired)>' from script/rails:6:inrequire’
from script/rails:6:in `’

On Thu, Feb 23, 2012 at 17:41, Bruno M. [email protected] wrote:

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

end

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?

-Dave


Dave A.: Available Cleared Ruby on Rails Freelancer
(NoVa/DC/Remote) – see www.DaveAronson.com, and blogs at
www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.com

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 …

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
:smiley:

was that Post actually actionmailer class?

saw ur exception coming from action mailer ?

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs