PostgreSQL和我不理解的命名空间模型有问题。
@photos = Profile::Photo.where(:attachable_id => id)
这会引发:
!! #<ActiveRecord::StatementInvalid: PG::UndefinedTable:
ERROR: relation "profile_photos" does not exist
LINE 1: SELECT "profile_photos".* FROM "profile_photos" WHERE "prof...
^
: SELECT "profile_photos".* FROM "profile_photos"
WHERE "profile_photos"."attachable_id" = 1>
我有一个模型app / models / profile / photo.rb,如:
class Profile::Photo < ActiveRecord::Base
mount_uploader :file, PhotoUploader
belongs_to :attachable, :polymorphic => true belongs_to :user,
:dependent => :destroy #belongs_to :profile, :foreign_key =>
'attachable_id', :dependent => :destroy
它表示关系不正确,但在命名模型之前,这种方法非常有效。我在这里忽略了什么?
答案 0 :(得分:1)
问题是错误的命名模型,我重构纠正多种格式并正确地重命名表来解决问题。