After creating a Rails module that generates JavaScript for a Google map, I encountered an issue. Whenever the user modifies the webpage, the observe_field
function is used to send a callback to the server in order to update the map's JavaScript without refreshing the entire page. However, I am struggling to find a suitable method for inserting this new JavaScript into the page.
<div id='my_div_1'>div1</div>
<%=
update_page_tag do |page|
page.replace_html 'my_div_1', "<script>alert('hi');</script>"
end
%>
It appears that using replace_html
only functions properly with non-script HTML content. When attempting to include the closing </script>
tag, it encounters errors.
The following link leads to a page that may provide insights on this issue: