2013-10-12 211 views
3

我真的很陌生,並且一直在努力構建應用程序。我最近在facebook上安裝了devise和omniauth,並在一段時間後取得了巨大的成功。當我閱讀設計時,我注意到Devise內置了一個「忘記密碼」模塊。devise忘記密碼設置

我已經搜遍了互聯網,對於我的生活還沒有想出如何設置它。有沒有指導?我一直在工作幾個小時,但我沒有真正有任何結果。我如何設置?我正在使用rails 4.0和最新版本的設計。

感謝,

路線

Omrails::Application.routes.draw do 
resources :boards 

resources :pins 

get 'about' => "pages#about" 

root :to => 'pins#index' 
resources :tests, :birthdays 
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } 
end 

制定遷移:

class DeviseCreateUsers < ActiveRecord::Migration 
def change 
create_table(:users) do |t| 
    ## Database authenticatable 
    t.string :email,    :null => false, :default => "" 
    t.string :encrypted_password, :null => false, :default => "" 

    ## Recoverable 
    t.string :reset_password_token 
    t.datetime :reset_password_sent_at 

    ## Rememberable 
    t.datetime :remember_created_at 

    ## Trackable 
    t.integer :sign_in_count, :default => 0, :null => false 
    t.datetime :current_sign_in_at 
    t.datetime :last_sign_in_at 
    t.string :current_sign_in_ip 
    t.string :last_sign_in_ip 

    ## Confirmable 
    # t.string :confirmation_token 
    # t.datetime :confirmed_at 
    # t.datetime :confirmation_sent_at 
    # t.string :unconfirmed_email # Only if using reconfirmable 

    ## Lockable 
    # t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts 
    # t.string :unlock_token # Only if unlock strategy is :email or :both 
    # t.datetime :locked_at 


    t.timestamps 
end 

add_index :users, :email,    :unique => true 
add_index :users, :reset_password_token, :unique => true 
# add_index :users, :confirmation_token, :unique => true 
# add_index :users, :unlock_token,   :unique => true 
end 
end 

User.rb

class User < ActiveRecord::Base 

# Include default devise modules. Others available are: 
# :token_authenticatable, :confirmable, 
# :lockable, :timeoutable and :omniauthable 
devise :database_authenticatable, 
    :registerable, 
    :rememberable, 
    :trackable, 
    :recoverable, 
    :validatable, 
    :omniauthable, 
    :omniauth_providers => [:facebook] 


# Setup accessible (or protected) attributes for your model 
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :birthday, :sex, :address, :mobile, :provider, :uid 

has_many :pins, :dependent => :destroy 
has_many :boards, :dependent => :destroy 
def self.find_for_facebook_oauth(auth, signed_in_resource=nil) 
user = User.where(:provider => auth.provider, :uid => auth.uid).first 
unless user 
    user = User.create(name:auth.extra.raw_info.name, 
         provider:auth.provider, 
         uid:auth.uid, 
         email:auth.info.email, 
         password:Devise.friendly_token[0,20]) 
end 
user 
end 
end 
+0

太棒了,謝謝!但是當我這樣做時,我得到一個錯誤「未定義的方法'new_password_path'爲#<#:0x483a308>」是我所要做的嗎? –

+0

剛剛將我的評論移至了ans,以防其他人在同一問題上絆倒 – rb512

+0

您可以運行耙路徑以查看您是否看到new_password路由?您需要重新啓動您的應用才能看到有效的更改 – rb512

回答

8

設計由10個模塊組成,您正在尋找的模塊可以恢復。在您的設計模型中,您需要爲設計添加:recoverable屬性。