Я обновлял свой сайт портфолио, куда я загрузил новый видеофайл, когда я проверил его на локальном сервере, страница выглядела хорошо, а затем решил обновить звездочки и загрузчик из-за проблем безопасности.
Я запустил bundle update
, а также bundle install
, я обновился до звездочек 3.2.7 и Bootstrap 4.1.2, тогда как до этого он был 4.0alpha.
Я исключил самоцвет Bootstrap как возможный.
Именно после этого моя страница блога и только моя страница блога сломались со следующим сообщением об ошибке:
PG :: UndefinedColumn: ОШИБКА: столбец blogs.topic_id не существует
из _blog_sidebar.html.erb
:
<div class="sidebar-module">
<h4>Topics</h4>
<% @side_bar_topics.each do |topic| %>
<p><%= link_to topic.title, topic_path(topic) %></p>
<% end %>
</div>
Это указывает на каждый цикл, говорящий, что я пропускаю поле topic_id
в модели Blog
?
Как это происходит путем обновления драгоценных камней?У кого-нибудь такое было раньше?Если да, то как вы это исправили?
Вот мой файл schema.rb
, где вы можете увидеть topic_id
:
ActiveRecord::Schema.define(version: 20170930175841) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "topics", force: :cascade do |t|
t.string "title"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "blogs", force: :cascade do |t|
t.string "title"
t.text "body"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "slug"
t.integer "status", default: 0
t.bigint "topic_id"
t.index ["slug"], name: "index_blogs_on_slug", unique: true
t.index ["topic_id"], name: "index_blogs_on_topic_id"
end
Я следовал соглашениям has_many
и belongs_to
: https://guides.rubyonrails.org/association_basics.html#the-has-and-belongs-to-many-association
blog.rb
:
class Blog < ApplicationRecord
enum status: {draft: 0, published: 1}
extend FriendlyId
friendly_id :title, use: :slugged
validates_presence_of :title, :body, :topic_id
belongs_to :topic
has_many :comments, dependent: :destroy
def self.special_blogs
all
end
def self.featured_blogs
limit(2)
end
def self.recent
order("created_at DESC")
end
end
topic.rb
:
class Topic < ApplicationRecord
validates_presence_of :title
has_many :blogs
def self.with_blogs
includes(:blogs).where.not(blogs: {id: nil})
end
end