2012-07-18 94 views
0

目標

我有一個員工模型,我需要在數據庫中種子 - 它不能是「可註冊的」。它不需要「可以確認」。設計資源登錄後不會登錄

在seeds.rb,我有:

Employee.destroy_all 
Employee.create(:email => "[email protected]", :password => "password", :password_confirmation => "password") 

的問題

我不能與員工的憑據登錄。閃光消息指出:

無效的電子郵件或密碼。

員工肯定在數據庫中。以下是控制檯輸出:

1.9.2p290 :048 > Employee.last 
Employee Load (1.0ms) SELECT "employees".* FROM "employees" ORDER BY "employees"."id" DESC LIMIT 1 
=> #<Employee id: 1, email: "[email protected]", encrypted_password: "$2a$10$QElm.sbv47i.F2H8P5pIvejzn4IeQbe3S8Rjvh34jp/g...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2012-07-18 16:00:09", updated_at: "2012-07-18 16:00:09"> 

登錄嘗試不增加員工記錄中的sign_in_count。

的設置

我色器件的設置應該是正確的,但我想知道如果我有一個洞。

在employee.rb:

devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable 

在routes.rb中:

devise_for :employees 

在schema.rb:

create_table "employees", :force => true do |t| 
    t.string "email",     :default => "", :null => false 
    t.string "encrypted_password",  :default => "", :null => false 
    t.string "reset_password_token" 
    t.datetime "reset_password_sent_at" 
    t.datetime "remember_created_at" 
    t.integer "sign_in_count",   :default => 0 
    t.datetime "current_sign_in_at" 
    t.datetime "last_sign_in_at" 
    t.string "current_sign_in_ip" 
    t.string "last_sign_in_ip" 
    t.datetime "created_at",        :null => false 
    t.datetime "updated_at",        :null => false 
end 

add_index "employees", ["email"], :name => "index_employees_on_email", :unique => true 
add_index "employees", ["reset_password_token"], :name => "index_employees_on_reset_password_token", :unique => true 

形式:

<h2>Sign In</h2 
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> 

    <%= f.label :email %> 
    <%= f.email_field :email %> 

    <%= f.label :password %> 
    <%= f.password_field :password %> 

    <% if devise_mapping.rememberable? -%> 
    <fieldset class="checkbox_container"> 
     <%= f.check_box :remember_me %> <%= f.label :remember_me %> 
    </fieldset> 
    <% end -%> 

    <div class="button_container"> 
    <%= f.submit "Sign in", :class => "button secondary" %> 
    </div> 
<% end %> 

回答

1

重新啓動服務器解決了問題。