# Method\_missing error......need some eyes for this one

**URL:** <https://www.ruby-forum.com/t/method-missing-error-need-some-eyes-for-this-one/111611>\
**Category:** Rails\
**Created:** [August 9, 2007, 2:58am UTC](https://www.ruby-forum.com/t/method-missing-error-need-some-eyes-for-this-one/111611 "2007-08-09T02:58:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wheresdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wheresdave](https://www.ruby-forum.com/u/wheresdave)\
**Post date:** [August 9, 2007, 2:58am UTC](https://www.ruby-forum.com/t/method-missing-error-need-some-eyes-for-this-one/111611/1 "2007-08-09T02:58:44Z")

</div>

Working through the tutorials in the RailsSpace book, and cannot  
figure out what I am doing wrong here. Full code for the edit function  
which is tossing the error as well as appropriate code from the model  
the actual error are pasted below.

Thank you for your help.

Dave

* * *

NoMethodError in UserController#edit

private method `correct\_password?’ called for #User:0x485ee28

RAILS\_ROOT: C:/instant\_rails/InstantRails/rails\_apps/puget/config/…  
Application Trace | Framework Trace | Full Trace

C:/instant\_rails/InstantRails/ruby/lib/ruby/gems/1.8/gems/  
activerecord-1.15.3/lib/active\_record/base.rb:1857:in `method_missing' #{RAILS_ROOT}/app/controllers/user_controller.rb:63:in`edit’

Request

Parameters: {“user”=\>{“password\_confirmation”=\>“blip”,  
“current\_password”=\>“blippi”, “password”=\>“bloppi”},  
“commit”=\>“Update”, “attribute”=\>“password”}

Show session dump

* * *

:user\_id: 6  
flash: !map:ActionController::Flash::FlashHash {}

Response  
Headers: {“cookie”=\>[], “Cache-Control”=\>“no-cache”}

* * *

user\_controller.rb

#Edit the user’s basic info.  
def edit  
@title = “Edit your User Information”  
@user = User.find(session[:user\_id])  
if param\_posted?(:user)  
attribute = params[:attribute]  
case attribute  
when “email”  
try\_to\_update @user, attribute  
when “password”  
if @user.correct\_password?(params)  
try\_to\_update @user, attribute  
else  
@user.password\_errors(params)  
end  
end  
end  
#For security purposes, never fill in the password fields.  
@user.clear\_password  
end

# Try to update the user, redirecting if successful.

def try\_to\_update(user, attribute)  
if user.update\_attributes(params[:user])  
flash[:notice] = “User #{attribute} updated.”  
redirect\_to :action =\> “index”  
end  
end

* * *

User.rb

#Return true if the password from params is correct.  
def correct\_password?(params)  
current\_password = params[:user] [:current\_password]  
password == current\_password  
end

```
 #Generate message for password errors.
 def password_errors(params)
   #Use User models valid? method to generate error message
   #for a password mismatch (if any)
   self.password = params[:user][:password]
   self.password_confirmation = params[:user]

```

[:password\_confirmation]  
valid?  
#The current password is incorrect, so add an error message.  
errors.add(:current\_password, “is incorrect”)  
end

---

<div class="post-metadata">

**Author:** ![wheresdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wheresdave](https://www.ruby-forum.com/u/wheresdave)\
**Post date:** [August 9, 2007, 3:00am UTC](https://www.ruby-forum.com/t/method-missing-error-need-some-eyes-for-this-one/111611/2 "2007-08-09T03:00:44Z")

</div>

Forgot to add that line 63 in the user\_controller.rb is

if @user.correct\_password?(params)

---

<div class="post-metadata">

**Author:** ![wheresdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wheresdave](https://www.ruby-forum.com/u/wheresdave)\
**Post date:** [August 9, 2007, 3:08am UTC](https://www.ruby-forum.com/t/method-missing-error-need-some-eyes-for-this-one/111611/3 "2007-08-09T03:08:44Z")

</div>

It’s saying that correct\_password? is a private method

private method `correct\_password?’ called for #User:0x485ee28

Move this above the private keyword in your User.rb file, or use the  
public  
keyword just above the method definition.

HTH  
Daniel

---

<div class="post-metadata">

**Author:** ![wheresdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wheresdave](https://www.ruby-forum.com/u/wheresdave)\
**Post date:** [August 9, 2007, 3:23am UTC](https://www.ruby-forum.com/t/method-missing-error-need-some-eyes-for-this-one/111611/4 "2007-08-09T03:23:45Z")

</div>

Works like a charm.

Thank you sir.
