Heroku Rails 迁移错误

Heroku Rails Migration error

我完成了为我的新 rails 应用程序创建用户注册,并且在我的本地计算机上开发时一切正常。但是在 heroku 上,部署的应用程序不会加载呈现 "new.html.erb" 的 signup_path。单击此路径给我一个错误,告诉我检查我的日志。

我已经检查了日志并尝试了几件事,但现在不知道该怎么做。以下是日志:http://pastebin.com/v1fVqLbL

错误是:

ActionView::Template::Error (undefined method `phone' for #<User:0x007f05a265c030>):

我尝试使用 heroku 运行 rake db:rollback 回滚我的迁移,但实际上似乎无法回滚任何迁移,因为 heroku rake db:status 仍然给我最后一个(phone 数字的索引)作为当前。

尝试回滚时有时会出现此错误:

ajhausdorf@rails-tutorial:~/workspace/AccessOBD (master) $ heroku run rake db:rollback
Running `rake db:rollback` attached to terminal... up, run.2007
  ActiveRecord::SchemaMigration Load (1.7ms)  SELECT "schema_migrations".* FROM "schema_migrations"
  ActiveRecord::SchemaMigration Load (1.4ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to AddIndexToUsersPhoneNumber (20150204094519)
   (1.2ms)  BEGIN
== 20150204094519 AddIndexToUsersPhoneNumber: reverting =======================
-- remove_index(:users, {:column=>:phone})
   (1.4ms)  ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Index name 'index_users_on_phone' on table 'users' does not exist/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:947:in `index_name_for_remove' 

new.html.erb

<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>

<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <%= form_for(@user) do |f| %>
      <%= render 'shared/error_messages' %>

      <%= f.label :name %>
      <%= f.text_field :name, class: 'form-control' %>

      <%= f.label :email %>
      <%= f.email_field :email, class: 'form-control' %>

      <%= f.label :phone, "Phone Number" %>
      <%= f.phone_field :phone, class: 'form-control' %>

      <%= f.label :password %>
      <%= f.password_field :password, class: 'form-control' %>

      <%= f.label :password_confirmation, "Confirm Your Password" %>
      <%= f.password_field :password_confirmation, class: 'form-control' %>

      <%= f.submit "Create my account", class: "btn btn-primary" %>
    <% end %>
  </div>
</div>

User.rb

class User < ActiveRecord::Base
  before_save { self.email = email.downcase }
  validates :name, presence: true, length: { maximum: 50 }
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence: true, length: { maximum: 255 },
                    format: { with: VALID_EMAIL_REGEX },
                    uniqueness: { case_sensitive: false }
  VALID_PHONE_REGEX = /\A(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}\z/
  validates :phone, presence: true, length: {maximum: 15},
                   format: { with: VALID_PHONE_REGEX },
                    uniqueness: true
  has_secure_password
  validates :password, length: { minimum: 6 }
end

我认为 phone 定义的生产架构:

ActiveRecord::Schema.define(version: 20150204094519) do

  create_table "users", force: :cascade do |t|
    t.string   "name"
    t.string   "email"
    t.datetime "created_at",      null: false
    t.datetime "updated_at",      null: false
    t.string   "password_digest"
    t.string   "phone"
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true
  add_index "users", ["phone"], name: "index_users_on_phone", unique: true

end

Heroku 迁移:

20150204074511_create_users.rb                  20150204093042_add_phone_number_to_users.rb
20150204081616_add_index_to_users_email.rb      20150204094519_add_index_to_users_phone_number.rb
20150204081750_add_password_digest_to_users.rb

如有必要,很高兴添加任何其他文件。我正在 运行 从 Hartl 的最新教程中获取最终的 gemfile。不知道还能做什么

我的问题是 git 没有跟踪我添加的任何会话文件,所以它们在我的本地计算机上但不在 github->heroku 上。我通过仅在 sessions_helper 上进行更改发现了这一点,然后提交到 git 只是为了得到一条消息,即没有对任何文件进行更改,但有几个(所有会话文件)未被跟踪。

发生这种情况是因为我首先使用了 git -am "commit message" 而不是 git add -A,因为我认为 -a 标志添加了所有内容。应该检查 git 以确保 sessions_helper.rb 在那里,所有的答案都告诉我检查这个,但我只是在我的本地机器上检查。