attachinary
attachinary copied to clipboard
Using with administrate gem
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
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