0

目标

我有一个需要在数据库中播种的员工模型——它不能是“可注册的”。它不需要是“可确认的”。

在seeds.rb中,我有:

Employee.destroy_all
Employee.create(:email => "me@company.com", :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: "me@company.com", 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。

设置

我的设计设置应该是正确的,但我想知道我是否有一个洞。

在雇员.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 %>
4

1 回答 1

1

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

于 2012-07-18T17:16:15.800 回答