Forum: Ruby on Rails Strange replace_html image error going from 1.2.5 to 2.1.0

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.
Dd859ff9f672a06dfab509e9ecaecc20?d=identicon&s=25 adeel (Guest)
on 2009-01-29 09:46
(Received via mailing list)
Hi I'm tasked with upgrading an old app from 1.2.5 to 2.1.0.

There is a basic image rotation triggered by a link_to_remote button.
The image gets rotated by Mini-Magick, saved, and then the div is
updated on the page to show the rotated image. This works fine in
1.2.5.

In 2.1.0 it does not. The image is being rotated and saved because a
refresh shows a rotated image. Furthermore, if I make the
image_tag's :title to be the image width (just to report something
that should change for debugging) I see the new width of the rotated
image when I hover over with the mouse. So it is being replaced but
I'm not seeing it. Very odd since it works just fine in 1.2.5.

Here are the code snippets:

views/products/show.rhtml -
<%= link_to_remote image_tag("arrow_turn_right.png"), :url =>
{ :action => "rotate", :id => @show_pic } %>

products_controller.rb -
  def rotate
    @show_pic = Asset.find_by_id(params[:id])
    @show_pic.rotate(params[:dir])
    @pics = @show_pic.product.images
    @show_pic.save!
    render :update do |page|
      page["product_pic"].replace_html  :partial => 'photo'
      page["asset_thumbs"].replace_html  :partial =>
'pic', :collection => @pics
    end
  end

_photo.rhtml -
<%= image_tag(@show_pic.public_filename(:large), :width => '300', :alt
=> @show_pic.product.title + string_tags
(@show_pic.product.tags), :title => @show_pic.width ) %>

This does throw the following Ajax response in Firebug's console:
try {
$("product_pic").update("\u003Cimg alt=\"acne \" src=\"/assets/
0000/0001/IMG_0086_large.JPG?1233213603
\" title=\"3264\" width=\"300\" /\u003E\n\n");
$("asset_thumbs").update("\u003Cspan class=\"thumb\"\u003E\n\t\u003Ca
href=\"/products/show?pic=1\"\u003E
\u003Cimg alt=\"Img_0086_thumb\" border=\"1\" height=\"50\" src=\"/
assets/0000/0001/IMG_0086_thumb.JPG
?1233213601\" width=\"50\" /\u003E\u003C/a\u003E\n\u003C/span\u003E");
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('$
(\"product_pic\").update(\"\\u003Cimg alt
=\\\"acne \\\" src=\\\"/assets/0000/0001/IMG_0086_large.JPG?1233213603\
\\" title=\\\"3264\\\" width=
\\\"300\\\" /\\u003E\\n\\n\");\n$(\"asset_thumbs\").update(\"\
\u003Cspan class=\\\"thumb\\\"\\u003E\
\n\\t\\u003Ca href=\\\"/products/show?pic=1\\\"\\u003E\\u003Cimg alt=\\
\"Img_0086_thumb\\\" border=\
\\"1\\\" height=\\\"50\\\" src=\\\"/assets/0000/0001/
IMG_0086_thumb.JPG?1233213601\\\" width=\\\"50\
\\" /\\u003E\\u003C/a\\u003E\\n\\u003C/span\\u003E\");'); throw e }

Any ideas?
978ed7ca309d5495078702096f9add03?d=identicon&s=25 Thomas r. Koll (tomk32)
on 2009-01-29 17:57
(Received via mailing list)
Hi Adeel,

On Jan 29, 9:45 am, adeel <adeel...@gmail.com> wrote:
> Hi I'm tasked with upgrading an old app from 1.2.5 to 2.1.0.
>
> There is a basic image rotation triggered by a link_to_remote button.
> The image gets rotated by Mini-Magick, saved, and then the div is
> updated on the page to show the rotated image. This works fine in
> 1.2.5.
> ....
>
> Any ideas?

Did you run a rake rails:update:scripts ?
I suspect the prototype files have changed and trouble you now.

About JS debugging, the error console (CMD-SHIFT-J on a Mac) will
give you a lot more information than the Firebug console usually does
(unless you configured it to do so).

ciao, tom

--
Thomas R. "TomK32" Koll <> http://ananasblau.com
just a geek trying to change the world
http://github.com/TomK32
Dd859ff9f672a06dfab509e9ecaecc20?d=identicon&s=25 adeel (Guest)
on 2009-01-29 18:49
(Received via mailing list)
I just ran rake rails:update:scripts but to no avail. It updated a
couple of scripts unrelated to prototype.
It still does not update the rotated image.

When I open the Firefox error console as you suggested, and I am
seeing:
Warning: Empty string passed to getElementById().
However this occurs even under 1.2.5 when it's working so I think this
is a red herring.

Did something else change in Rails 2 for replacing objects?
This topic is locked and can not be replied to.