My problem is quite complicated.
In my project, I have to use static <script> tag to generate dynamic graph with links inside it. for example in a erb.html file, I wrote.
1. ### this will generate a tree view in my page. 2. <script> 3. create_tree(){###}; 4. </script> 5. <div id='tree'></div>
However, the <script> section above is not static, I have to write a helper to dynamically generate it. so it becomes to
1. <%= generate_tree_view(:id=>1) ## this will generate the <script> section and insert them in the page 2. <div id='tree'></div>
But, right now, my problem is I have to call this tree view page by ajax like this
1. ## view file show.erb.html 2. ... 3. <%= link_to_remote 'see_tree', :url=>{:action=>'view_tree', :id=>1} > 4. <div id='view_tree'></div> 5. ...
1. ## controller file tree_controller.rb 2. ... 3. def view_tree 4. ### get some parameters, say 'tree_parameter' array 5. render :update do |page| 6. page.replace_html 'view_tree', :partial=>'view_tree', :object=>tree_parameter 7. end 8. end 9. ...
1. ## partial page _view_tree.erb.html 2. <%= generate_tree_view(:tree_parameter=>view_tree) 3. <div id='tree'></div>
I thought this should work because it actually worked if I directly use the generate_tree_view help in the show.erb.html. But however, when the partial page is called by ajax, the <script> section which is generated by generate_tree_view didn't show up in the page. The final page only shows this:
1. ## view file show.erb.html, saw by firebug 'cause it is the only way I can see a rendered page. 2. ... 3. <div id='view_tree'> 4. <div id='tree'></div> 5. </div> 6. ...
It seems they got executed by the javascript call instead of just display it.
So, what should I do if I just want to inject a <script> section in a rendered page.
I'm not sure whether you have already got my idea, but I really appreciate it if you help me solve this problem. Thank you.