Skip to content

Using with administrate gem #148

Open

Description

@samwebgit

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

Activity

  1. estiens commented on Jun 23, 2017

    @estiens

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions