metaco57
metaco57

Reputation: 155

How to fix the Internal 500 Error in a rails application

I keep getting this error when I try to run my application. It states that there is an undefined method error in the application, but doesn't state where. The closest error I could find as tangible was this:

NameError (undefined local variable or method `confirmed_at' for #<User:0x6049800>):

I'm not sure which part this is directing to. Could someone please tell me what this error means?

This is the code for the devise_users file

class DeviseCreateUsers < ActiveRecord::Migration
def change
   create_table(:users) do |t|
    ## Database authenticatable
    t.string :name,               null: false, default: ""
    t.string :email,              null: false, default: ""
    t.string :encrypted_password, null: false, default: ""
    t.string :about
    t.string :avatar
    t.string :cover

    ## Recoverable
    t.string   :reset_password_token
    t.datetime :reset_password_sent_at

    ## Rememberable
    t.datetime :remember_created_at

    ## Trackable
    t.integer  :sign_in_count, default: 0, null: false
    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.string   :confirmation_token
    t.datetime :confirmed_at
    t.datetime :confirmation_sent_at
    t.timestamps null: false
    ## Confirmable
    # t.string   :confirmation_token
    # t.datetime :confirmed_at
    # t.datetime :confirmation_sent_at
    # t.string   :unconfirmed_email # Only if using reconfirmable

    ## Lockable
    # t.integer  :failed_attempts, default: 0, null: false # Only if lock  strategy is :failed_attempts
    # t.string   :unlock_token # Only if unlock strategy is :email or :both
    # t.datetime :locked_at


    t.timestamps null: false
  end

  add_index :users, :email,                unique: true
  add_index :users, :reset_password_token, unique: true
  add_index :users, :confirmation_token, unique: true
  # add_index :users, :confirmation_token,   unique: true
  add_index :users, :unlock_token,         unique: true
 end
 end

There are not any other places within the application where the method is called, therefore the error states that the method is being called somewhere when it isn't. How can I fix this error?

Upvotes: 0

Views: 199

Answers (2)

Dillon Hafer
Dillon Hafer

Reputation: 156

Your migration file DeviseCreateUsers created a table users in the database, and one of the columns in that table is confirmed_at.

In your app/models/user.rb file you probably declared your devise configuration like:

class User < ActiveRecord::Base
  devise :registerable, :confirmable

  ...
end

ActiveRecord::Base, the class User is inheriting from, automatically creates "getter" and "setter" methods for database columns (i.e. confirmed_at), so the method #confirmed_at should already be defined.

So if the method is "missing", you may not have run the database migrations (e.g. rake db:migrate)

Upvotes: 1

jkdev
jkdev

Reputation: 11738

Search your code for confirmed_at -- it seems you used it somewhere without defining it first.

It would be nice if the error message gave you a file name and a line number, but (depending on which text editor or IDE you're using) you might be able to run a search on the entire Rails app at once.

My guess is you called the confirmed_at method on a user object (user_1.confirmed_at, for example) and the method wasn't defined in class User.

Upvotes: 0

Related Questions