Rails 4: Paperclip and rails_admin "undefined method `attachment_definitions' error"
Asked Answered
E

3

7

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.

Expiate answered 8/7, 2013 at 9:59 Comment(2)
also having this issue. please update if you've found an answer!Subsume
See github.com/sferik/rails_admin/issues/1691Pet
S
8

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

Swallowtail answered 22/7, 2013 at 21:50 Comment(2)
I've confirmed this fix also works for Rails 4.0.0 on Ruby 2.0.0-p195Cannes
Damn! Thank you very much Tyrel. I can't believe this doesn't work with the latest version of PaperclipKwei
L
3

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!

Lawrenson answered 4/12, 2013 at 2:50 Comment(2)
You saved one project to die. Thank you so much . It really helped. I found columns in the database for which rails_admin is looking for attachment defination on the model which is not there. paperclip and rails_admin are fine. There is a issue in db and model level.Amby
I had a similar problem. In my case was because under the hood I was calling attachment_definitions before the has_attached_file methodLicence
H
1

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)

Houseclean answered 23/9, 2015 at 12:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.