# Drag & drop, file renaming, updation using ajax doesnt work?

**URL:** <https://www.ruby-forum.com/t/drag-drop-file-renaming-updation-using-ajax-doesnt-work/154712>\
**Category:** Rails\
**Created:** [December 3, 2008, 6:21am UTC](https://www.ruby-forum.com/t/drag-drop-file-renaming-updation-using-ajax-doesnt-work/154712 "2008-12-03T06:21:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [December 3, 2008, 6:21am UTC](https://www.ruby-forum.com/t/drag-drop-file-renaming-updation-using-ajax-doesnt-work/154712/1 "2008-12-03T06:21:14Z")

</div>

Dear all,

I was struck in a task for changing the banner images.

Actually my task was,

I have a folder banner inside images. It contains some sample gif  
images. I need to display the current banner image.

Like i have banner.gif, banner1.gif, banner2.gif inside my banner  
folder. my banner image is always banner.gif.

I have an controller advertisements and no model.

I have a list page, which has two parts like, current banner image(div)  
which display the banner image(banner.gif) and next part is banner list  
which displays all images in banner folder(banner.gif, banner1.gif,  
banner2.gif).

The list is a draggable one and current banner is a droppable. so from  
the list any one can drag a image and drop in curreent banner image, so  
that the banner image should change and list should also change because  
always my banner image would be banner.gif

So on drag and drop i have renamed the file names inside banner folder.  
So the renaming of file names works fine as a result of drag and drop  
but it was not updated in the view. Could any one suggest on the above  
issue.

Note:  
Even if i restart the server the view was not updated but when i clear  
cache in the browser and refresh the page, now the view is updates. So  
could any one please suggest and help me to complete my task.

Here with i have attached the code:

## Advertisement Controller
`
class AdvertisementsController < ApplicationController
#-------------------------------------------------------

def list
#------
$bannerimage = “banner.gif”
@files = Dir.glob(“public/images/banner/*.gif”)
end

def update
#-----------
```
if params[:id] != "banner.gif"
   if request.xhr?
      render :update do |page|
        $bannerimage=''
        $bannerimage = "banner.gif"

```
a=File.rename(“public/images/banner/banner.gif”,“public/images/banner/temp.gif”)
b=File.rename(“public/images/banner/#{params[:id]}”,“public/images/banner/banner.gif”)
c=File.rename(“public/images/banner/temp.gif”,“public/images/banner/#{params[:id]}”)
page.replace_html “currentbannerimage”,
:partial => “currentbanner”,
:locals => { :variable => $bannerimage.strip
}
```
        @newfiles = Array.new
        @newfiles = Dir.glob("public/images/banner/*.gif")
        page.replace_html "allbanners",
                       :partial => "searchresults",
                       :collection => @newfiles
      end
   end
end

```
end
`

list.rhtml  
#------------

`

  
```
    <%= render :partial => 'currentbanner', :locals =>
               { :variable => $bannerimage } %>

```
  

```
Drag images from the list and drop in current banner image

<div id="allbanners">

  <%= render :partial => 'searchresults', :collection => @files %>

</div>

```
  
<%= drop_receiving_element “currentbannerimage”,
:url => { :action => “update” } %>

`

\_searchresults.rhtml  
#-----------------------------

`
<%a = searchresults.split('public/images/banner/')%>

<%= image_tag “banner/#{a}”, :id => a %>

<%= draggable_element “#{a}”, :revert => true %>
`

\_currentbanner.rhtml  
#---------------------------

`
Drop
images here
<%= image_tag “banner//#{variable}” %>
`

Thanks in advance,

Regards,  
Jose Martin
