做heroku run rails db:migrate
後,我得到這個錯誤的堆棧跟蹤其中包括:Heroku的運行軌道分貝:遷移
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "categories" does not exist: CREATE TABLE "products" ("id" serial primary key, "title" character varying, "description" character varying, "category_id" integer, "picture" character varying, "video" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_fb915499a4"
FOREIGN KEY ("category_id") REFERENCES "categories" ("id"))
然後我跑heroku run:detached rake db:migrate
和它的工作。
但是,當我去到現場的網址,我得到這個錯誤:
ActiveRecord::StatementInvalid in WelcomeController#index
PG::UndefinedTable: ERROR: relation "products" does not exist LINE 1: SELECT "products".* FROM "products" ORDER BY "products"."cr...^: SELECT "products".* FROM "products" ORDER BY "products"."created_at" ASC LIMIT $1
編輯:
class WelcomeController < ApplicationController
def index
end
end
而且錯誤指向該行:
@all_products = Product.order(created_at: :asc).last(4)
定義在application_controller.rb
像這樣:
def getProducts
@all_products = Product.order(created_at: :asc).last(4)
end
在welcome/index.html.erb
中使用了@all_products
變量來顯示最近4次上傳的產品。
它被稱爲像這樣:
<div class="text-center">
<% if @all_products.present? %>
<% @all_products.each do |p| %>
<a href="<%= p.picture() %>" data-toggle="lightbox" data-gallery="example-gallery" data-title="<%= p.title %>">
<%= image_tag(p.picture.url, size: '200x200', class: 'rounded') %>
</a>
<% end %>
<% end %>
</div>
看到上面的更新 – JohnnyDevv
上面的另一個更新 – JohnnyDevv
你有在數據庫中的記錄? –