Iqbal Bakhsh
Iqbal Bakhsh

Reputation: 11

Why am I getting an uninitialized constant error when the model file exists?

I'm getting the following error in pry after creating the model. I think I have all the pieces in place so cant be sure why. I haven't created the controller yet but I think I should still be able to access my model in pry before setting up the model.

NameError: uninitialized constant Deal

app/models/deal.rb

class Deal < ApplicationRecord
end

db/schema.rb


  create_table "deals", force: :cascade do |t|
    t.string "origin_city"
    t.string "destination_city"
    t.date "fly_out"
    t.date "check_in"
    t.date "check_out"
    t.date "trip_end"
    t.float "flight_price"
    t.float "hotel_price"
    t.date "date"
    t.integer "number_nights"
    t.string "hotel_link"
    t.string "search_results_link"
    t.string "flight_link"
    t.string "region"
    t.string "country"
  end

Upvotes: 0

Views: 1239

Answers (1)

Iqbal Bakhsh
Iqbal Bakhsh

Reputation: 11

The code is correct. The problem was in opening pry and not the rails console to check the model connection.

bundle exec rails c

Using the above and going into pry via the console vs. just opening it works.

Upvotes: 1

Related Questions