2012-02-17 33 views
0

我在使用忘記密碼方法訪問用戶的電子郵件時遇到問題。如何在不使用此方法創建新用戶的情況下訪問電子郵件。我在user.rb模型中有send_new_password方法。在導軌中訪問忘記密碼方法的用戶

def forgot_password 
    if request.post? 
     user = User.find_by_email(params[:user][:email]) 
     puts user 
     if user and user.send_new_password 
     flash[:message] = "A new password has been sent by email." 
     # redirect_to root_path 
     else 
     flash[:warning] = "Couldn't send password" 
     end 
    end 
    end 

這是我忘記密碼頁面

<h1>Forgot Password</h1> 
<%= form_for(@user) do |f| %> 
    <%= render 'shared/error_messages', :object => f.object %> 
    <div class="field"> 
    <%= f.label :email %><br /> 
    <%= f.text_field :email %> 
    </div> 
<div class="actions"> 
    <%= f.submit "Submit" %> 
    </div> 
<% end %> 

回答

1

你可能想要做

form_for(User.new) 

,因爲你不會有任何物體投入@user

+0

也就是說創建訪問權限錯誤。 – 2012-02-17 19:43:08

+0

請更具體。何時發生 - 表單呈現時,還是提交時?日誌中是否有錯誤?嘗試添加日誌消息以瞭解錯誤發生的位置。 – Kelvin 2012-02-17 21:03:01