hoilzz
hoilzz

Reputation: 105

ActionView::Template::Error (PG::UndefinedColumn: ERROR: column “user_id” does not exist

I deployed my project on heroku.

crackeryourwardrobe.heroku.com is my website.

When I click facebook login, I'm getting this error in heroku logs

PG::UndefinedColumn: ERROR:  column "user_id" does not exist
SELECT "products".* FROM "products"  WHERE (user_id = 1)  

my view.rb

<% if session[:user_id] %>
  <% @account_products.order(created_at: :desc).in_groups_of(3) do |product_group| %>
    <div class = "row">
      <% product_group.compact.each do |product| %>
        <div class="col-md-4">

products.rb class Product < ActiveRecord::Base has_many :line_items, dependent: :destroy has_many :wardrobe_item, dependent: :destroy mount_uploader :item, ItemUploader end

wardrobe_item.rb class WardrobeItem < ActiveRecord::Base belongs_to :product belongs_to :user end

user.rb

class User < ActiveRecord::Base
    has_many :wardrobe_items, dependent: :destroy

database.yml

default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

schema.rb

  create_table "products", force: true do |t|
    t.string   "title"
    t.text     "brand"
    t.string   "image_url"
    t.decimal  "price"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "item"
    t.integer  "user_id",    limit: 255

product.rb

class Product < ActiveRecord::Base
    has_many :line_items, dependent: :destroy
    has_many :wardrobe_item, dependent: :destroy
    mount_uploader :item, ItemUploader 

end

wardrobe_item.rb

class WardrobeItem < ActiveRecord::Base
    belongs_to :product
    belongs_to :user
end

schema.rb

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

  create_table "line_items", force: true do |t|
    t.integer  "product_id"
    t.integer  "cart_id"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "quantity",   default: 1
  end

  create_table "products", force: true do |t|
    t.string   "title"
    t.text     "brand"
    t.string   "image_url"
    t.decimal  "price"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "item"
    t.integer  "user_id",    limit: 255
  end

  create_table "stores", force: true do |t|
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "users", force: true do |t|
    t.string   "provider"
    t.string   "uid"
    t.string   "name"
    t.string   "oauth_token"
    t.datetime "oauth_expires_at"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "cart_id"
    t.integer  "wardrobe_item_id"
  end

  create_table "wardrobe_items", force: true do |t|
    t.integer  "product_id"
    t.integer  "user_id"
    t.datetime "created_at"
    t.datetime "updated_at"

I don't know how to solve it... help.....please...

Upvotes: 0

Views: 1610

Answers (1)

sungpi
sungpi

Reputation: 21

This is happening because User model and Product model is not thoroughly connected.

In User model, add up this code

user.rb

class User < ActiveRecord::Base
    has_many :wardrobe_items, dependent: :destroy
    has_many :products, through: :wardrobe_items # this is code

it would make your connection to product, through user :)

Upvotes: 0

Related Questions