# How to refresh Image through ajax request

**URL:** <https://www.ruby-forum.com/t/how-to-refresh-image-through-ajax-request/157924>\
**Category:** Rails I18n\
**Created:** [January 16, 2009, 4:34pm UTC](https://www.ruby-forum.com/t/how-to-refresh-image-through-ajax-request/157924 "2009-01-16T16:34:40Z")\
**Posts on this page:** 1\
**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 16, 2009, 4:34pm UTC](https://www.ruby-forum.com/t/how-to-refresh-image-through-ajax-request/157924/1 "2009-01-16T16:34:40Z")

</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

Thanks in Advance
