# How to refresh Image through ajax request

**URL:** <https://www.ruby-forum.com/t/how-to-refresh-image-through-ajax-request/157979>\
**Category:** Rails\
**Created:** [January 17, 2009, 8:33am UTC](https://www.ruby-forum.com/t/how-to-refresh-image-through-ajax-request/157979 "2009-01-17T08:33:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sauravsuman012](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@sauravsuman012](https://www.ruby-forum.com/u/sauravsuman012)\
**Post date:** [January 17, 2009, 8:33am UTC](https://www.ruby-forum.com/t/how-to-refresh-image-through-ajax-request/157979/1 "2009-01-17T08:33:32Z")

</div>

Hi all ,  
I am very new for ruby. I am using Ajax Request(Rmagick in controller)  
for changing image on my DIV but the problem is it refresh for first  
time only then after i have to refresh the browser always. If anybody  
having any solution, Please let me know . I am posting my code here

# Code in rhtml file

\<%= form\_remote\_tag({:url=\>{:controller=\>‘image\_builders’, :action  
=\>‘index’}, :update =\>‘photo’})%\>

  
Type \<%= submit\_tag 'Create Image' %\> 
**Image:**

```
      <div id="photo" style="width:99%;">

      </div>
      </div>

```

===============================================================================  
code in controller

def index  
@Rows =20  
@Cols = 120  
@alpha = params[:alpha].to\_i  
@margin = params[:margin].to\_i  
if params[:height].to\_i \>9000 || params[:width].to\_i \> 9000  
if params[:height].to\_i \>9000  
params[:height] = 8999  
end  
if params[:width].to\_i \> 9000  
params[:width] = 8999  
end  
end  
if params[:height] && params[:width]  
@Rows =params[:height].to\_i  
@Cols = params[:width].to\_i  
end  
@Start = params[:input\_field\_1]  
@End = params[:input\_field\_2]  
if params[:type] == ‘gradation’  
fill = Magick::GradientFill.new(0, 0, 0, @Cols, @Start, @End)  
img = Magick::Image.new(@Rows, @Cols, fill)  
img.opacity = @alpha/ 127.0 \* Magick::TransparentOpacity if  
@alpha != 0  
img\_new = img.rotate(90)  
if params[:reverse]  
img\_rev = img\_new.rotate(270)  
img\_rev.write(“public/images/xyz.jpg”)  
render :text =\> “ ![](https://test.ruby-forum.com/images/xyz.jpg)”  
else  
img\_new.write(“public/images/xyz.jpg”)  
render :text =\> “ ![](https://test.ruby-forum.com/images/xyz.jpg)”  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![sauravsuman012](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@sauravsuman012](https://www.ruby-forum.com/u/sauravsuman012)\
**Post date:** [January 17, 2009, 12:21pm UTC](https://www.ruby-forum.com/t/how-to-refresh-image-through-ajax-request/157979/2 "2009-01-17T12:21:51Z")

</div>

On 17 Jan 2009, at 07:33, Kumar S. wrote:

> Hi all ,  
> I am very new for ruby. I am using Ajax Request(Rmagick in controller)  
> for changing image on my DIV but the problem is it refresh for first  
> time only then after i have to refresh the browser always. If anybody  
> having any solution, Please let me know . I am posting my code here

Is it your browser caching the image?

Fred
