Paperclip : undefined method 'attachment_definitions' in Rails

Paperclip is popular gem used in rails project to provide attachment feature in your model. It is very flexible and easy to use.

I mostly use paperclip for my project if I need to provide attachment feature. You can get more detail about how to use paperclip from github repo.

I was working on project in which I have used RailsAdmin for administration. I was having a situation where I need to remove feature of attachment from model. With a view of changes, I just removed attachment code from my model which is :

has_attached_file :attachment_attr_name

I was trying to access model from RailsAdmin and faced error saying

undefined method `attachment_definitions'

After checking all aspects, I get to know that I forget to remove fields from database / schema.rb . To do that I have generated new migration file which removes that fields from database and modify schema.rb. My migration was containing following code :

remove_attachment :table_name, :attachment_attr_name

For example : remove_attachment :users, :avatar

I ran that migration with rake db:migrate  and it fixes the problem.

Hope that helps!!!