2015-12-20 64 views
0

我的目標是要求使用Ajax進行密碼恢復。未定義的方法`succesfully_sent?'',Rails 4和設計密碼恢復

我的形式:

<%= form_for(resource,:html => {"data-parsley-validate" => true,:id=>"password-recover-modal",:class=>"password-recover-modal"},:remote=> true,format: :json,as: resource_name, url: password_path(resource_name)) do |f| %> 

    <div class="form-group">  
     <%= f.email_field :email, autofocus: true ,:class=> "user-input form-control", :id=>"email",:placeholder=>"E-pasts",required: true%>            
    </div> 

    <%= f.submit "Atgūt paroli",:class=> "blue-button btn btn-default"%> 

<%end%> 

我不得不重寫設計密碼控制器:

class PasswordsController < Devise::PasswordsController 

respond_to :json, only: [:create] 

    def create 
    user = resource_class.send_reset_password_instructions(resource_params) 

      if succesfully_sent?(user) 
       render json: { data: "something" }, status: 200 
      else 
       render json: { data: "something bad" }, status: 400 
      end 
    end 

end 

電子郵件與密碼恢復指令發送成功。

問題:

我不能讓Ajax響應或者有錯誤發送該電子郵件或沒有。

Eror消息:

undefined method `succesfully_sent' 
+1

其中succesfully_sent定義在哪裏? – Someonation

+1

檢查您的拼寫:'successful_sent?' – evanbikes

回答

2

看起來像一個簡單的拼寫錯誤。

該方法是successfully_sent?並且在DeviseController中定義,所以應該可用於從它繼承的任何控制器。