Using Dropbox Chooser within ActiveAdmin

We use Dropbox quite heavily in Loudcloud. I’m working on an internal CRM system and since all of our files are on Dropbox anyway, I figured it would be super helpful to just have to link to our Dropbox files.

Here are the relevant files:

# app/inputs/dropbox_input.rb
class DropboxInput < Formtastic::Inputs::FileInput
  def to_html
    input_wrapping do
      label_html <<
      builder.text_field(method, input_html_options.merge({ type: "dropbox-chooser", style: "visibility: hidden;" }))
    end
  end
end

# app/admin/invoice.rb
ActiveAdmin.register Invoice do
  form do |f|
    within @head do
      script src: "https://www.dropbox.com/static/api/1/dropins.js", id: "dropboxjs", type: "text/javascript", "data-app-key" => "APP_KEY_HERE"
    end

    # ....

    f.inputs "Official Receipt" do
      f.input :or_file_url, as: :dropbox, label: "OR File URL"
    end

    # ....
  end
end

Resources:
https://www.dropbox.com/developers/dropins/chooser/js
http://stackoverflow.com/questions/12809237/insert-specifics-js-in-the-header-of-some-pages-active-admin
https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/inputs/base/html.rb
http://stackoverflow.com/questions/12465020/getting-formtastic-in-activeadmin-to-use-custom-form-input-builder