migrationもDBも全く触っていないのになぜかmigrationでエラーが発生する問題に手を撮られて4時間も格闘しました

こちらがエラー全文

ActiveAdmin::DatabaseHitDuringLoad: Your file, app/models/job_from_web.rb (line 5), caused a database error while Active Admin was loading. This is most common when your database is missing or doesn't have the latest migrations applied. To prevent this error, move the code to a place where it will only be run when a page is rendered. One solution can be, to wrap the query in a Proc. Original error message: Could not find table 'job_from_webs'

どうやらactiveadmin関連で問題が発生しており、
scopeの部分でそれが発火してるみたいです

こちらが該当コード

scope :find_by_prefecture, -> (prefecture_code) {
    joins(:prefectures).where({is_public: true, is_finished: false, prefectures: {prefecture_code: prefecture_code.to_i}})
  }

解決策は、ルーティングのactiveadminを下記のコードに書き換えればエラーをスルーできるようです

# config/routes.rb
ActiveAdmin.routes(self) rescue ActiveAdmin::DatabaseHitDuringLoad

参考記事

Rails 4 + ActiveAdmin compatibility (Migration error) #71

コメントをどうぞ

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA