简体   繁体   中英

Heroku Rails Migration error

I finished creating user sign-up for my new rails app and everything worked fine in development on my local machine. But on heroku the deployed app will not load the signup_path which renders "new.html.erb". Clicking this path gives me an error telling me to check my logs.

I've checked the logs and have tried several things but don't know what to do now. Here are the logs: http://pastebin.com/v1fVqLbL

The error is:

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

I've tried rolling back my migrations using heroku run rake db:rollback but can't seem to actually any of the migrations to rollback because heroku rake db:status still gives me the last (index to phone numbers) as the current.

Getting this error sometimes when trying to rollback:

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

My production schema, where I believe phone is defined:

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 Migrations:

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

Happy to add any other files if necessary. I'm running the final gemfile from Hartl's newest tutorial. Don't know what else to do

My problem was that git wasn't tracking any of the sessions files I had added, so they were on my local computer but not on github->heroku. I found this out by making a change only on sessions_helper, then committing to git only to get a message that there were no changes to any files but several (all of the sessions files) were untracked.

This happened because I used git -am "commit message" rather than git add -A first bc I thought the -a flag added everything. Should've checked git to make sure sessions_helper.rb was there, all the answers told me to check this but I was only checking on my local machine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM