From c9e4d0f3454cf89a0823febd00bd2811d672260e Mon Sep 17 00:00:00 2001 From: Kaito Date: Thu, 28 Jul 2011 18:54:31 +0800 Subject: [PATCH] in design,after online editing,return json url,callback not finish --- app/assets/javascripts/design_temp.js | 8 +++++++- app/controllers/admin/designs_controller.rb | 10 +++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/design_temp.js b/app/assets/javascripts/design_temp.js index 2a8f0f2c..00d751e1 100644 --- a/app/assets/javascripts/design_temp.js +++ b/app/assets/javascripts/design_temp.js @@ -6,6 +6,7 @@ function r_editor(tgetUrl,tpostUrl,tfilename,toption){ editor.filename = tfilename; editor.getUrl = tgetUrl; editor.postUrl = tpostUrl; + editor.nodeToBeChanged="" editor.width = toption['width']; editor.height = toption['height']; var html=''; @@ -27,7 +28,12 @@ function r_editor(tgetUrl,tpostUrl,tfilename,toption){ }); }; editor.send = function(){ - $.post(editor.postUrl,{filename:editor.filename,context:html.children("textarea").val(),authenticity_token:$('meta[name=csrf-token]').attr('content')}); + callback_for_send = function(data){ + editor.postUrl = data; + alert($(this).attr("path")); + }; + $.post(editor.postUrl,{filename:editor.filename,context:html.children("textarea").val(),authenticity_token:$('meta[name=csrf-token]').attr('content')},callback_for_send,"json"); + }; editor.destroy = function(){ html.remove(); diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb index 257a8188..aa72d82f 100644 --- a/app/controllers/admin/designs_controller.rb +++ b/app/controllers/admin/designs_controller.rb @@ -30,18 +30,18 @@ class Admin::DesignsController < ApplicationController file_to_removed = files.find{ |obj| obj.file_filename == filename } - type = file_to_removed._type + type = file_to_removed._type + new_file = "" Dir.mktmpdir('design_temp'){ |dir| temp_file = File.new(dir+'/'+filename,'w+') temp_file.write params[:context] replace_target = eval("@design.#{type.downcase.pluralize}") - a = replace_target.build(:file => temp_file,:to_save=>true) - debugger + new_file = replace_target.build(:file => temp_file,:to_save=>true) file_to_removed.destroy @design.save - debugger temp_file.close - } + } + render :json => new_file.file.url end