jquery - Return JSON response to image upload in RUBY -


i'm newbie ruby.the question might sound worthless of you. sorry that. i'm struggling find solution problem past 6 hours.

aim:

i have html editor. here, want insert image editor have been uploaded via file dialog.

what did

once, user uploads image via file dialog, return path image( 1 have been constructed dynamically @ server side) . i'm using jquery ajaxupload method uploading image.

where did struggle

i have no problem saving uploaded image using ruby.

class imagecontroller < applicationcontroller   def upload     post = datafile.save(params[:upload])     #how send  json response here   end end 

i need send uploaded image url browser json response follows

{ 'url' : 'app/uploadedimage/***.**'} 

in js, use url src image element follows

$.ajax({         url: 'image/upload',         *         *         *         success: function (returndata) {                  var image = document.createelement('img');                  j(image).attr('src',returndata.url).appendto(editor);         },         error: function(){                  alert("error in ajax form submission");             } 

thanks in advance answers & suggestions.

you can specify json return in controller action.

def controller_action   # using sample model , methods   obj = modelclass.create_new_object(params)   url = obj.get_image_url   render json: {url: url} end 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -