Is it possible to somehow implement it so that after the download a picture immediately appears so that you can immediately edit it with jcrop

var uploadify_script_data = {}; $('#uploadify').uploadify({ uploader : '/assets/uploadify.swf', script : '<%=pictures_path%>', cancelImg : '/images/cancel.png', auto : true, multi : true, removeCompleted : true, scriptData : uploadify_script_data, onComplete : function(event, ID, fileObj, doc, data){ } }); 

I try this code but it produces 405

 def create render json: {image_path: image.file_path} @restaurant = current_user.restaurants.build(restaurant_params) if @restaurant.save flash[:success] = 'Поздравляем! Ваше заведение создано!' redirect_to restaurant_profile_index_path else render 'new' end end def restaurant_params params.require(:restaurant).permit(:image) end 
  • Most likely, yes, but you will have to parse the requests made and write the logic of their processing on the server. Libraries do not always fit well together, so sometimes you still have to study what they are based on. - D-side

1 answer 1

I did not find it on off. site uploadify some used options. Perhaps an older version is used.

But in general, we are interested in the onUploadSuccess event.

It should be something like:

 $('#uploadify').uploadify({ 'swf': '/assets/uploadify.swf', 'uploader': '<%=pictures_path%>', //собственно, урл куда загружать файл 'onUploadSuccess': function(file, data, response) { $('#uploaded_container').attr('src', data.image_path) } }) 

To make it work, you need:

  1. Add in the html-code page tag <img id="uploaded_container" src="">
  2. Process the image on the server side accordingly. For example:

PicturesController:

 def create # код, который валидирует и сохраняет файл render json: {image_path: image.file_path} end 
  • Thanks, I'll try - Silentium
  • I don’t understand why but gives 500 when loading, and in the NameError console (undefined local variable or method `image 'for ...) - Silentium
  • Perhaps, due to the fact that in the action code image used without initialization? And in general, judging by the code, this is quite a html 'ny action, which creates restaurants, and does not handle the loading of pictures. - anoam
  • I don’t understand, let's say there is a big form where there are many fields, and there are fields for uploading photos, is it possible to upload photos and they immediately appear for further change, but you didn’t click in the send form - Silentium