From 16b3ad011718deeb12d683fef4e899df265fdb92 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Fri, 18 Jul 2014 16:55:01 +0000 Subject: [PATCH] [media-panel-improvements] Error handling --- app/controllers/my_profile/cms_controller.rb | 9 ++++++--- app/views/cms/_text_editor_sidebar.html.erb | 2 +- app/views/cms/media_upload.js.erb | 10 +++------- app/views/layouts/_javascript.html.erb | 2 +- public/javascripts/media-panel.js | 5 +++++ public/javascripts/string.js | 987 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public/stylesheets/application.css | 10 ++++++++++ 7 files changed, 1013 insertions(+), 12 deletions(-) create mode 100644 public/javascripts/string.js diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index dc96283..aa58b5d 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -323,10 +323,13 @@ class CmsController < MyProfileController def media_upload parent = check_parent(params[:parent_id]) if request.post? - @file = UploadedFile.create(:uploaded_data => params[:file], :profile => profile, :parent => parent) unless params[:file] == '' + begin + @file = UploadedFile.create!(:uploaded_data => params[:file], :profile => profile, :parent => parent) unless params[:file] == '' + @file = FilePresenter.for(@file) + rescue Exception => exception + render :text => exception.to_s, :status => :bad_request + end end - @file = FilePresenter.for(@file) - #render :text => article_list_to_json([file]), :content_type => 'text/plain' end def published_media_items diff --git a/app/views/cms/_text_editor_sidebar.html.erb b/app/views/cms/_text_editor_sidebar.html.erb index 4cfe970..00dc506 100644 --- a/app/views/cms/_text_editor_sidebar.html.erb +++ b/app/views/cms/_text_editor_sidebar.html.erb @@ -30,7 +30,7 @@