dare ruby
2008-Dec-03 05:21 UTC
Drag & drop, file renaming, updation using ajax doesnt work?
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 ------------------------------------- <code> 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 </code> list.rhtml #------------ <code> <div id=''forms''> <div id="currentbannerimage"> <%= render :partial => ''currentbanner'', :locals => { :variable => $bannerimage } %> </div> </div> <div id="allbannerimage" > Drag images from the list and drop in current banner image <div id="allbanners"> <%= render :partial => ''searchresults'', :collection => @files %> </div> </div> <%= drop_receiving_element "currentbannerimage", :url => { :action => "update" } %> </div> </code> _searchresults.rhtml #----------------------------- <code> <%a = searchresults.split(''public/images/banner/'')%> <div id="bannerlist" style="margin-right :5px;float:right;width :320px;background : #CCE4F2;margin-top :10px;padding :20px;border :1px solid white;"> <%= image_tag "banner/#{a}", :id => a %> </div> <%= draggable_element "#{a}", :revert => true %> </code> _currentbanner.rhtml #--------------------------- <code> <div style="color:white;padding-left:100px;padding-bottom:3px;">Drop images here</div> <%= image_tag "banner//#{variable}" %> </code> Thanks in advance, Regards, Jose Martin -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---