Replace_html + javascript

Hi all,

This is my first post to the list, so I hope it gets through and I
don’t do anything wrong :slight_smile:

Here’s the issue I’m having…

I have an rjs that’s doing:
page.replace_html ‘myid’, :partial => ‘my_partial’

And in my my_partial I have:

And this breaks my replace_html, and I get a javascript error in
firebug that looks like it’s not escaping it right.

Does anyone else experience this? Anyone have any suggestions on how
to fix it?

TIA
–hax

Can’t you just do

page.replace_html ‘myid’, :partial => ‘my_partial’
page.alert(‘foo’)

in the RJS template and skip the javascript in the partial?

Zack

Hi hax,

hax wrote:

This is my first post to the list, so I hope it gets through and I don’t
do anything wrong :slight_smile:

Welcome aboard!

I have an rjs that’s doing:
page.replace_html ‘myid’, :partial => ‘my_partial’

And in my my_partial I have:

If it makes sense to do it in the RJS template, you can just do
page.alert(‘foo’). If that doesn’t make sense, posting more of the code
might help you get a better answer.

Best regards,
Bill

hax wrote:

Let me know what you think.

Not quite the same thing, but as a data point: I have one app that uses
a lot of Ajax editing. The link that shows initially is a
link_to_remote. The method it points to renders javascript via render
:template. The template it renders, in turn, calls replace_html with a
partial. The partial includes a form_remote_tag.

All of this works fine, no problems with the escaping or anything. It
seems like a vaguely comparable situation, so I thought I’d mention it.

–Al Evans

Not quite the same thing, but as a data point: I have one app that
uses
a lot of Ajax editing. The link that shows initially is a
link_to_remote. The method it points to renders javascript via render
:template. The template it renders, in turn, calls replace_html with a
partial. The partial includes a form_remote_tag.

All of this works fine, no problems with the escaping or anything. It
seems like a vaguely comparable situation, so I thought I’d mention
it.

Aha. This isn’t exactly the same thing, but it got me thinking, and
after a good night’s sleep, here’s what the problem actually was:

In my rjs I was rendering a partial that had tags in it…
but this works if you just set up a test case. The problem actually
was with Sean Treadway’s responds_to_parent (http://
sean.treadway.info/articles/2006/05/29/iframe-remoting-made-easy) and
my iframe trickery.

As it turns out, his plugin seems to have the escaping problem.

Sorry this wasn’t actually related to the core like I had originally
thought, but thank you for prompting me to fix it :slight_smile:

If anyone needs more details, feel free to mail me.

–hax

Welcome aboard!

Thanks, this list looks really helpful :slight_smile:

I have an rjs that’s doing:
page.replace_html ‘myid’, :partial => ‘my_partial’

And in my my_partial I have:

If it makes sense to do it in the RJS template, you can just do
page.alert(‘foo’). If that doesn’t make sense, posting more of the
code might help you get a better answer.

I knew I should have posted more code :slight_smile:

It actually looks more like this:

RJS: page.replace_html ‘myid’, :partial => ‘my_partial’

_my_partial.rhtml:
@foo.each do |f|

"> <%= f.my_string %>

<%= in_place_editor "foo_#{f.id}", :url => { :action => 'update_my_string', :id => f.id } %> end

So, although it’s the same problem as my alert() above from the point
of view of “it’s escaping wrong”… I don’t think I can do the
in_place_editor in the rjs like page.in_place_editor().

I guess I could look to see how in_place_editor does it’s thing,
strip out the javascript part, and << it into page. Then include an
extra line in my partial that doesn’t try to do the in_place_editor
if it’s an rjs page_replace. But that seems unclean, and it’d also
seem like if replace_html isn’t broken by not being able to include a

in it... it should raise an error, or have a note in the rdoc, or something, so people like me aren't just staring blankly at it :) Let me know what you think. --hax

Try,

page.replace_html ‘myid’, :partial => ‘my_partial’, :content_type =>
‘text/javascript; charset=utf-8’

And have following in your RJS :
alert(‘foo’);

This should work theoretically.

On 7/21/06, hax [email protected] wrote:

And in my my_partial I have:


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


rm -rf / 2>/dev/null - http://null.in

“Things do not happen. Things are made to happen.” - JFK

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs