Forum: Ruby on Rails RJS wierdness - Content div display js code

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.
E74a19a983b0da1c671de90b341e7c06?d=identicon&s=25 James Hughes (Guest)
on 2006-06-08 20:11
(Received via mailing list)
Hi,

I have a link_to_remote name 'Show notes', which calls an action that
uses this RJS template:

page.replace "notes_remote", :partial => "notes/hide_notes_link"
page.insert_html :top, "notes_list", :template => "notes/list"
page.visual_effect :highlight, 'notes_list', :duration => 3

Works great. The 'Show notes' link is replaced with a 'Hide notes'
link, and a 'notes_list' div has some content displayed in it. The
highlight effect works as expected. Except...

The content that is displayed is, wait for it, the generated
javascript code: (!)

Element.replace("notes_remote", "Hide notes"); new
Insertion.Top("notes_list", null); new
Effect.Highlight("notes_list",{duration:3});

I went through Cody Fauser's 'add a fox' tutorial[1], and it works
fine. Looking at the headers and content in Firebug, the only
difference I can see in the tutorial example is that the js code is
wrapped in a try/catch block.

Content-type is text/javascript, and I am including all the necessary
js files (as evidenced by the fact that the ajax bits "work". I have
also done rake 'update_javascripts'.

Fresh eyes appreciated.
jh


[1] http://www.codyfauser.com/articles/2005/11/20/rail...




--
James Hughes
Web application developer
Vancouver, BC

"Developing a coherent political analysis is in many respects
contingent upon an ability to connect one context to another, a
process not dissimilar to playing the kid's game of dot-to-dot."
 - Ward Churchill, from '"A Government of Laws"?'
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-06-08 20:27
James Hughes wrote:
> The content that is displayed is, wait for it, the generated
> javascript code: (!)

Make sure you are not using the :update option in the link_to_remote.
The :update takes whatever is returned by the server and sticks it in
the specified DOM id.  SO it's used when the server returns HTML.  When
the server returns javascript, in the case of RJS, it should simply be
executed, and the javascript itself decides what gets manipulated.

In case I am wrong, post you link_to_remote call cause that might be
where the problem is.
E74a19a983b0da1c671de90b341e7c06?d=identicon&s=25 James Hughes (Guest)
on 2006-06-08 20:39
(Received via mailing list)
On 6/8/06, Alex Wayne <rubyonrails@beautifulpixel.com> wrote:
> In case I am wrong, post you link_to_remote call cause that might be
> where the problem is.

Alex, thanks so much, that was exactly the problem.

Now to figure out why the options_for_render param to insert_html is
generating null.

jh

--
James Hughes
Web application developer
Vancouver, BC

"Developing a coherent political analysis is in many respects
contingent upon an ability to connect one context to another, a
process not dissimilar to playing the kid's game of dot-to-dot."
 - Ward Churchill, from '"A Government of Laws"?'
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-06-08 21:13
James Hughes wrote:
> Alex, thanks so much, that was exactly the problem.
>
> Now to figure out why the options_for_render param to insert_html is
> generating null.

because :template is not a valid option?  I think you have to use
partial.
This topic is locked and can not be replied to.