I’m using
render :update do |page|
page.replaca_html :element , :partial => ‘apartial’
end
Is this inside a view, or up in a controller?
}
I simplified the output.
My problem is that no script tag is generated and the code is not
executed!
How can I fix this?
Inside a view, use update_page_tag(). I think render :update works
different
inside a view. You could, for example, stack up many render :updates
inside
one view tag.
But prefer using a controller, because “that’s what everyone else does”.
If
possible!
I’m using
render :update do |page|
page.replaca_html :element , :partial => ‘apartial’
end
My problem is that no script tag is generated and the code is not
executed!
What did you expect ? You’ve asked controller to update HTML, so
controller
generated javascript to do that. You can then execute it on page.
But if you used e.g. remote_function with :update parameter, then
Ajax.Request
expect some HTML from server to put into element you’ve specified.
I think it is (almost always) better to use remote_function without
:update
argument, because it gives you more flexibility (not just updating
contents
of single element).
render :update is meant be used in the controller as a response to an
AJAX request, it returns pure javascript that will be executed by tha
AJAX code that called the action … so of course there are no
tags.
Anyway, I’m using this do display the errors in a specific part of my
html, so this is no response to a request.
The following quote is from the manual “Use this in your Ajax response
bodies, either in a tag or as plain JavaScript sent with a
Content-type of “text/javascript””.
So, this is my question, how do I do that? How can I add the script
tags?
Anyway, I’m using this do display the errors in a specific part of my
html, so this is no response to a request.
Everything’s a responds to a request. Someone asked if you were doing
a response to an Ajax request. You are apparently injecting JavaScript
when the page first paints.
The following quote is from the manual “Use this in your Ajax response
bodies, either in a ’ around the string it returns.
If you are inside a view, go
Note that there are few reasons to do the former. Yet there might be
many reasons to do the latter - sharing the first-paint code with the
update code, for example.
And note a purist would need the type=‘text/javascript’, the // CDATA
escape things. I don’t know what function returns those.