SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy 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.
    Have a good day.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,044
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    Just a quick wild guess. Maybe it's a case thing? i.e. user vs. User

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the code:
    Code:
             
       email = Mailer.deliver_reset_password(@User, password)
       Mailer.deliver(email)
    Should be
    Code:
             
       email = Mailer.create_reset_password(@User, password)
       Mailer.deliver(email)
    Also the method reset_password(user, password) belongs in the Mailer class and not the model class.

    P.S. @User should be @user.

  4. #4
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guys that wasn't the issue. The only thing I can come up with is Ruby doesn't allow me to pass arrays as arguments.
    Have a good day.

  5. #5
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it to work. Error was the view variables were not instant variables. So much for the Rails procket reference.
    Have a good day.

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Darren884 View Post
    Rails procket reference.
    The clue is in the title.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •