Forum: Ruby How to refresh Image through ajax request

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
047c2e2a6349db15db769e3ad46cf936?d=identicon&s=25 Kumar Saurav (sauravsuman012)
on 2009-01-16 16:26
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
================================================================================
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2009-01-17 07:29
(Received via mailing list)
On Jan 16, 2009, at 07:25 , Kumar Saurav wrote:

> 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

pls ask these q's in the rubyonrails forums/lists.
047c2e2a6349db15db769e3ad46cf936?d=identicon&s=25 Kumar Saurav (sauravsuman012)
on 2009-01-17 08:31
Ryan Davis wrote:
> On Jan 16, 2009, at 07:25 , Kumar Saurav wrote:
>
>> 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
>
> pls ask these q's in the rubyonrails forums/lists.

I don't have access of that forum due to lost of the password and i
think it belongs to this forum also so i put it here.
Thanks
047c2e2a6349db15db769e3ad46cf936?d=identicon&s=25 Kumar Saurav (sauravsuman012)
on 2009-01-17 08:34
Kumar Saurav wrote:
> Ryan Davis wrote:
>> On Jan 16, 2009, at 07:25 , Kumar Saurav wrote:
>>
>>> 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
>>
>> pls ask these q's in the rubyonrails forums/lists.
>
> I don't have access of that forum due to lost of the password and i
> think it belongs to this forum also so i put it here.
> Thanks

Sorry i misunderstood.

Thanks for the suggestion
8a934bca2d929e50550e5d97e4e0ddcc?d=identicon&s=25 AGoofin (Guest)
on 2009-01-17 16:40
(Received via mailing list)
On Jan 17, 2:33 am, Kumar Saurav <sau...@cipher-tech.com> wrote:
>
> > I don't have access of that forum due to lost of the password and i
> > think it belongs to this forum also so i put it here.
> > Thanks
>
> Sorry i misunderstood.
>
> Thanks for the suggestion
> --
> Posted viahttp://www.ruby-forum.com/.

Have you tried: periodically_call_remote?

or (non-AJAX): <META HTTP-EQUIV="Refresh" CONTENT="300">
047c2e2a6349db15db769e3ad46cf936?d=identicon&s=25 Kumar Saurav (sauravsuman012)
on 2009-01-19 06:01
AGoofin wrote:
> On Jan 17, 2:33�am, Kumar Saurav <sau...@cipher-tech.com> wrote:
>>
>> > I don't have access of that forum due to lost of the password and i
>> > think it belongs to this forum also so i put it here.
>> > Thanks
>>
>> Sorry i misunderstood.
>>
>> Thanks for the suggestion
>> --
>> Posted viahttp://www.ruby-forum.com/.
>
> Have you tried: periodically_call_remote?
>
> or (non-AJAX): <META HTTP-EQUIV="Refresh" CONTENT="300">

Hi
As i sent you code i have to refresh the whole form not a single element
. So please let me know if you have any solution regarding to whole
form.

Thanks in Advance.
699c00ad35f2755810b4aa5f423d73e2?d=identicon&s=25 Albert Schlef (alby)
on 2009-01-19 10:20
Kumar Saurav wrote:
> I am using Ajax Request(Rmagick in controller)
> for changing image on my DIV but the problem is it refresh for first
> time only
[...]
>         render :text => "<img src='/images/xyz.jpg' />"

Perhaps the browser caches this image. The browser isn't aware that it
has changed. I suggest you add some random string to the image's URL.
E.g. /image/xyz.jpg?56543653.
047c2e2a6349db15db769e3ad46cf936?d=identicon&s=25 Kumar Saurav (sauravsuman012)
on 2009-01-19 11:31
Albert Schlef wrote:
> Kumar Saurav wrote:
>> I am using Ajax Request(Rmagick in controller)
>> for changing image on my DIV but the problem is it refresh for first
>> time only
> [...]
>>         render :text => "<img src='/images/xyz.jpg' />"
>
> Perhaps the browser caches this image. The browser isn't aware that it
> has changed. I suggest you add some random string to the image's URL.
> E.g. /image/xyz.jpg?56543653.

Hi i just hard code the path like "public/images/xyz.jpg?1234" but after
that i get the following error


no encode delegate for this image format `public/images/xyz.jpg?1234'

RAILS_ROOT: C:/Myworkspace/css_menu_builder - import
Application Trace | Framework Trace | Full Trace

app/controllers/image_builders_controller.rb:68:in `write'
app/controllers/image_builders_controller.rb:68:in `index'


So please help me how can i add any random string after the URL
Please let me help ...
Thanks in advance
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2009-01-19 11:55
(Received via mailing list)
On Jan 19, 2009, at 02:30 , Kumar Saurav wrote:

> So please help me how can i add any random string after the URL
> Please let me help ...

this DOES NOT belong on this list.
699c00ad35f2755810b4aa5f423d73e2?d=identicon&s=25 Albert Schlef (alby)
on 2009-01-19 11:58
Kumar Saurav wrote:
> Albert Schlef wrote:
>> Kumar Saurav wrote:
>> [...]
>>>         render :text => "<img src='/images/xyz.jpg' />"
>>
>> Perhaps the browser caches this image. The browser isn't aware that it
>> has changed. I suggest you add some random string to the image's URL.
>> E.g. /image/xyz.jpg?56543653.
>
> Hi i just hard code the path like "public/images/xyz.jpg?1234" but after
> that i get the following error
>
> no encode delegate for this image format `public/images/xyz.jpg?1234'

You added that random string in img_rev.write(). No good. Add it to the
URL. In other words, add it in the <img> tag. You need to send the
browser '<img src="pic.jpg?some-changing-string">' instead of just '<img
src="pic.jpg">'.
699c00ad35f2755810b4aa5f423d73e2?d=identicon&s=25 Albert Schlef (alby)
on 2009-01-19 12:03
Ryan Davis wrote:
> On Jan 19, 2009, at 02:30 , Kumar Saurav wrote:
>
>> So please help me how can i add any random string after the URL
>> Please let me help ...
>
> this DOES NOT belong on this list.

I'm not sure it doesn't belong here. It's an HTML/HTTP issue, not a
Rails one. It doesn't involve the Rails API, AFAICS. But I'll submit to
your judgment and forward Kumar to that other list in my next reply.
047c2e2a6349db15db769e3ad46cf936?d=identicon&s=25 Kumar Saurav (sauravsuman012)
on 2009-01-19 13:46
Albert Schlef wrote:
> Kumar Saurav wrote:
>> Albert Schlef wrote:
>>> Kumar Saurav wrote:
>>> [...]
>>>>         render :text => "<img src='/images/xyz.jpg' />"
>>>
>>> Perhaps the browser caches this image. The browser isn't aware that it
>>> has changed. I suggest you add some random string to the image's URL.
>>> E.g. /image/xyz.jpg?56543653.
>>
>> Hi i just hard code the path like "public/images/xyz.jpg?1234" but after
>> that i get the following error
>>
>> no encode delegate for this image format `public/images/xyz.jpg?1234'
>
> You added that random string in img_rev.write(). No good. Add it to the
> URL. In other words, add it in the <img> tag. You need to send the
> browser '<img src="pic.jpg?some-changing-string">' instead of just '<img
> src="pic.jpg">'.

Hi i solved out that problem through your suggestion
Thanks. Thanks a lot

And Hi Ryan
I am ensuring you that i will try to post in the right list

Thanks for your support also.
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-01-19 16:31
(Received via mailing list)
Albert Schlef wrote:

> Perhaps the browser caches this image. The browser isn't aware that it
> has changed. I suggest you add some random string to the image's URL.
> E.g. /image/xyz.jpg?56543653.

Why not use image_path()? Then the number is not random, but a time
signature,
right?
This topic is locked and can not be replied to.