Search code examples
ruby-on-railsrubymodelckeditor

Conflict between Picture model and Ckeditor::Picture model


In my existing Rails project, I create Picture model.

class Picture < ActiveRecord::Base
    belongs_to :user
end

And then, when adding Ckeditor to my project, I have to create another Picture model under ckeditor directory like this

class Ckeditor::Picture < Ckeditor::Asset
  ...
end

In my user model, I have this association class User < ActiveRecord::Base has_many :pictures end

However, I cannot use user.pictures. Whenever I make this statement, the following error comes up:

Expected /home/xxx/app/models/ckeditor/picture.rb to define Picture

How can I solve this issue?


Solution

  • I managed to resolve my issue by renaming the Picture class into UserPicture and use table_name to set its corresponding table in database. And then in User model:

    has_many :pictures, class_name: 'UserPicture'