Argument not passing to model...
I am trying to use a method from a model when reset the users password.
This is my code in my controller:
Code Ruby:
def reset_password
# Process the password reset.
if params[:user] && params[:user][:username] && params[:user][:email]
if params[:user][:username].empty? || params[:user][:email].empty?
render :update do |page|
page.replace_html 'notice', '<span class="error">Please enter a username and an email.</span>'
end
else
if Users.exists?(:username => params[:user][:username], :email => params[:user][:email])
password = 'test'
@User = Users.find(:first, :conditions => {:username => params[:user][:username], :email => params[:user][:email]}, :select => 'first_name, email')
@User.password = password
@User.save
email = Mailer.deliver_reset_password(@User, password)
Mailer.deliver(email)
render :update do |page|
page.replace_html 'notice', '<span class="success">Your password has been reset and sent to you.</span>'
page.visual_effect :fade, 'user_reset_password'
end
else
render :update do |page|
page.replace_html 'notice', '<span class="error">Wrong username and/or email.</span>'
end
end
end
else
# Render nothing.
render :action => false, :layout => false
end
end
However, when I call reset_password it says the user argument is not getting passed, and I just don't understand why. Here is the method code:
Code Ruby:
def reset_password(user, password)
recipients user.email
from 'noreply@mysite.com'
subject 'Temporary New Password'
body render_message('reset_password.txt.erb'), :first_name => user.first_name, :password => password
end
Can someone please help? Why isn't this working? Thanx.