Forum: Rails I18n How to refresh Image through ajax request

Posted by Kumar Saurav (sauravsuman012)
on 2009-01-16 16:34
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'})%>
        <dl style="width:450px">
          <dt>Type</dt>
<!--  form element -->


</dl>
          <%= submit_tag 'Create Image' %>
        </div>

<!--  End of form -->
<!--  Preview Area  -->
<div>
          <label><b>Image:</b></label>

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

          </div>
          </div>

<!--  End of Preview Area -->

===============================================================================
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 => "<img src='/images/xyz.jpg' />"
      else
        img_new.write("public/images/xyz.jpg")
        render :text => "<img src='/images/xyz.jpg' />"
      end
    end
end
================================================================================

Thanks in Advance
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.