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
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 `’
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?
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)
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