Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using with administrate gem #148

Open
samwebgit opened this issue May 18, 2017 · 1 comment
Open

Using with administrate gem #148

samwebgit opened this issue May 18, 2017 · 1 comment

Comments

@samwebgit
Copy link

samwebgit commented May 18, 2017

I have a products class and using attachinary/cloudinary for images. Decided to try out the administrate gem and this is what I am getting: _uninitialized constant Attachinary::FileDashboard
Extracted source (around line #263): constant.const_get(name) else candidate = constant.const_get(name) next candidate if constant.const_defined?(name, false) next candidate unless Object.const_defined?(name)

Any idea on how to solve this? Thank you

@estiens
Copy link

estiens commented Jun 23, 2017

I am unaware of where you are getting this error, however I have successfully used attachinary with administrate. You have to do something link this.

rails generate administrate:field attachinary

# app/fields/attachinary_field.rb
require "administrate/field/base"

class AttachinaryField < Administrate::Field::Base
  def path_for_image
    data.path
  end

  def to_s
    data
  end
end
# app/views/attachinary_field/_form.html.erb

<div class="field-unit__label">
  <%= f.label field.attribute %>
</div>
<div class="field-unit__field">
  <%= f.attachinary_file_field field.attribute %>
</div>
# app/views/attachinary_field/_show.html.erb

<%= cl_image_tag(field.path_for_image, { size: '200x200', crop: :fit }) %>

In your actual dashboard file, you will declare the field like this

ATTRIBUTE_TYPES = {
    id: Field::Number,
    date: Field::DateTime,
    alternative_picture: Field::AttachinaryField,
  }.freeze

Then you can just use :alternative_picture in your FORM_ATTRIBUTES, etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants