2012-07-18 45 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

重新启动服务器解决了问题。