4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/active_admin_modal_upload/dsl.rb', line 4
def modal_uploads(options={})
config.resource_class.send(:include, ::ActiveAdminModalUpload::Uploadable)
uploader = options[:mounted_uploader] ||= :image
config.resource_class.send(:allows_upload, uploader)
collection_action :create_upload, method: :post do
@upload_model = options[:model] ||= active_admin_config.resource_class
@model = @upload_model.new(upload_resource_params)
if @model.save
respond_to do |format|
format.html {
render :json => [@model.to_jq_upload].to_json,
:content_type => 'text/html',
:layout => false
}
format.json {
render :json => { files: [@model.to_jq_upload] }, status: :created
}
end
else
render :json => [{:error => "custom_failure"}], :status => 304
end
end
member_action :destroy_upload, method: :delete do
@upload_model = options[:model] ||= active_admin_config.resource_class
@model = @upload_model.find(params[:id])
@model.destroy
render :json => true
end
end
|