Skip to content

Instantly share code, notes, and snippets.

@balvig
Last active August 23, 2020 14:22
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save balvig/e77749fd3d2d4c05f34b to your computer and use it in GitHub Desktop.
Save balvig/e77749fd3d2d4c05f34b to your computer and use it in GitHub Desktop.
Active Admin Cloudinary
# app / assets / javascripts / active_admin.js
//= require active_admin/base
//= require jquery.ui.widget
//= require jquery.iframe-transport
//= require jquery.fileupload
//= require cloudinary/jquery.cloudinary
//= require attachinary
//= require attachments
# config / initializers / active_admin_cloudinary.rb
# The Active Admin equivalent of putting this in your application layout:
# <head>
# <%= cloudinary_js_config %>
# </head>
module ActiveAdmin
module Views
module Pages
class Base < Arbre::HTML::Document
alias_method :original_build_head, :build_active_admin_head
def build_active_admin_head
original_build_head
within @head do
text_node cloudinary_js_config
end
end
end
end
end
end
# app / assets / javascripts / attachments.js
jQuery ->
$('.attachinary-input').attachinary()
# app / inputs / formtastic_attachinary_input.rb
class FormtasticAttachinaryInput
include Formtastic::Inputs::Base
attr_reader :attachinary_options
def to_html
input_wrapping do
label_html <<
template.builder_attachinary_file_field_tag(method, @builder, { html: input_html_options })
end
end
end
@saifuddin
Copy link

Fantastic! Doesn't have preview or upload bar, but works like a charm!

edit: thanks Joeyjoejoe too

@Joz84
Copy link

Joz84 commented Dec 11, 2016

Super! Tkts a lot!!!

Just an update comment. If you have this errors : “couldn't find file 'jquery.ui.widget” on rails 5., you need to install in your gemfile :
gem "jquery-fileupload-rails"

and change in # app / assets / javascripts / active_admin.js :
//= require jquery.ui.widget
//= require jquery.iframe-transport
//= require jquery.fileupload

by

//= require jquery-fileupload/vendor/jquery.ui.widget
//= require jquery-fileupload/jquery.iframe-transport
//= require jquery-fileupload/jquery.fileupload

See: https://github.com/tors/jquery-fileupload-rails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment