2016年1月2日土曜日

Railsでdecorate_columnsエラー

Rails(というかActiveRecord)では「type」というカラム名は予約語らしいです。

実際にtypeをカラム名に使ってみると、こんなエラーが出ます。

ActiveRecord::SubclassNotFound - The single-table inheritance mechanism failed to locate the subclass: 'hogehoge'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite SolutionDimInfo.inheritance_column to use another column for that information.:
このエラー文なら「あ、予約語使っちゃてる」とわかると思います。

問題なのは、typeに存在するクラスを代入してしまっている時です。

seed-fuのデータが以下のように設定されているとします。
Hoge.seed do |hoge|
 hoge.type = "Float"
end
これを読みこんで、コントローラorモデルで使っているページにアクセスします。

すると、先ほどとは違ったエラーが出るのです!
NoMethodError - undefined method `decorate_columns' for Float:Class:
decorate_columnsでググっても原因がわからず、新年早々アホなエラーに時間をかけてしまいました。

0 件のコメント:

コメントを投稿