我不理解 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
它说关系不正确,但这在为模型命名空间之前非常有效。我在这里忽略了什么?
最佳答案
问题是命名模型不正确,我重构以更正复数格式并正确重命名表格,这解决了问题。
关于ruby-on-rails - 命名空间模型 + postgresql 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20006302/