问题
I am using rails_admin and paperclip but installing rails_admin with a model having paperclip attributes has_attached_file
throws an error
undefined method `attachment_definitions'
I am using Rails 4 and rails_admin at master git branch and protected attributes gem.
回答1:
I am on rails 3 still but ran into the same issue. I am fairly certain its an issue with the latest paperclip and rails_admin. I backed paperclip down to paperclip (3.4.2) and everything works.
Another thing of note I am using ruby 1.9.3
So for the newer rails guys/galls
In your gem file
gem "paperclip", "3.4.2"
then bundle update
not sure if other versions will work but I know that one does
回答2:
Are you properly calling has_attached_file in the model itself?
I had ruby (1.9.3), Rails (4.0.1), paperclip (3.5.2) and rails_admin (0.5.0) working without error. Then I created a new model. It had all the usual paperclip columns and should have worked. But I got that same error message.
My problem (duh) was that I neglected to configure paperclip in the model itself, but had the paperclip columns in my schema. I wasn't calling has_attached_file ... in my model.
has_attached_file :img...
I loosely recall that rails_admin sniffs certain paperclip smelling columns and acts on it. So I had the paperclip like columns, which rails_admin detected, but never called has_attaached_file resulting in the error. And that error makes sense, there were indeed no "attachment_definitions" to speak of!
回答3:
The problem might be that has_attached_file
declaration is missing in your model. However this is a bug in rails_admin (in paperclip factory). I submitted the pull request here: https://github.com/sferik/rails_admin/pull/2410
Until then, you can use rails_admin from this branch: https://github.com/drap-hr/rails_admin/tree/v0.7.0-fixes (which is 0.7.0 version with paperclip factory fixed)
来源:https://stackoverflow.com/questions/17523849/rails-4-paperclip-and-rails-admin-undefined-method-attachment-definitions-er