Skip to content

Commit 13f8200

Browse files
committed
#5 Fix AJAX attachment remove problem
1 parent 0b2d9aa commit 13f8200

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

app/assets/javascripts/kebapage/media.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Dropzone.options.mediaDropzone = {
88
addRemoveLinks: true,
99
init: function () {
1010
return this.on('removedfile', function(file) {
11+
console.log(file.xhr);
1112
if (file.xhr) {
1213
return $.ajax({
1314
url: "" + ($("#media-dropzone").attr("action")) + "/" + (JSON.parse(file.xhr.response).id),

app/assets/stylesheets/kebapage/application.css

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
* You're free to add application-wide styles to this file and they'll appear at the top of the
99
* compiled file, but it's generally better to create a new file per style scope.
1010
*
11-
*= require bootstrap-wysihtml5/core-b3
12-
*= require hierapolis
11+
*= require bootstrap-wysihtml5
1312
*= require dropzone/dropzone
1413
*= require_self
1514
*= require_tree .
16-
*/
15+
*/
16+
17+
@import 'hierapolis';
18+
@import 'bootstrap-wysihtml5/core-b3';

app/controllers/kebapage/media_controller.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
module Kebapage
44
class MediaController < ApplicationController
5-
65
def index
76
@media = Medium.order('attachment_updated_at DESC')
87
@medium = Medium.new
98
end
109

1110
def create
1211
@medium = Medium.create(attachment: params[:attachment ])
13-
render json: @media
12+
render json: @medium
1413
end
1514

1615
def destroy
@@ -22,7 +21,6 @@ def destroy
2221
else
2322
redirect_to media_path
2423
end
25-
2624
end
2725
end
2826
end

app/models/kebapage/medium.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module Kebapage
22
class Medium < ActiveRecord::Base
33
has_attached_file :attachment
4+
5+
validates_attachment_size :attachment, less_than: 5.megabytes
6+
validates_attachment_content_type :attachment, content_type: ['image/jpeg', 'image/png', 'application/pdf']
47
end
58
end

app/views/kebapage/media/index.html.haml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
%td
3636
= media.attachment_updated_at.to_date
3737
%td.action
38-
%a.btn.btn-success{href: media.attachment.url }
39-
%i.icon-zoom-in
38+
%a.btn.btn-success{href: media.attachment.url, target: '_blank' }
39+
%i.icon-eye-open
4040
= link_to medium_path(media), method: :delete, data: { confirm: I18n.t('kebapage.ru_sure') }, class: 'btn btn-danger' do
4141
%i.icon-trash

0 commit comments

Comments
 (0)