# Problems with calling javascript containing dynamic content in partial page

**URL:** <https://www.ruby-forum.com/t/problems-with-calling-javascript-containing-dynamic-content-in-partial-page/177530>\
**Category:** Rails\
**Created:** [October 19, 2009, 8:22pm UTC](https://www.ruby-forum.com/t/problems-with-calling-javascript-containing-dynamic-content-in-partial-page/177530 "2009-10-19T20:22:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lu\_Liu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e9bcb4/32.png) [@Lu\_Liu](https://www.ruby-forum.com/u/Lu_Liu)\
**Post date:** [October 19, 2009, 8:22pm UTC](https://www.ruby-forum.com/t/problems-with-calling-javascript-containing-dynamic-content-in-partial-page/177530/1 "2009-10-19T20:22:46Z")

</div>

Hi all,

I am trying to call some javascript function defined in partial page  
“\_results.html.erb”. But it seemed that the js functions in the page  
are unrecognizable, and I have no idea why.

In my app, I have an “index” action/view containing an form\_remote\_tag  
sending the ajax request to a “process” action. After some calculation  
in the “process” action, it passes a local variable to a result page  
and renders it partially. Briefly, the index.html.erb looks like:

# index.html.erb

\<% form\_remote\_tag :url =\> ‘process’,  
:id =\> ‘inputs’,  
:update =\> {:success =\> ‘result\_div’, :failure =\>  
‘document.write(request.responseText)’} do -%\>

# some input tags here

\<%= submit\_tag “calculate” %\>  
\<% end -%\>

In controller#index, there is nothing. In controller#process, there is  
the calculation code which will cost several seconds, after that it is  
the render method:

def process

# calculation code which will generate a result - @ruby\_result -

which is an ruby object  
render :partial =\> ‘results’, :locals =\> {:ruby\_result =\>  
@ruby\_result}  
end

And in \_results.html.erb:

show result

The update of the result\_div is totally ok, but when I click on the  
“show result”, nothing happened. I tried putting the showResult()  
function in the index.html.erb. Then it can be found by the  
\_results.html.erb. However the problem is that the ruby\_result can  
only be got after the process. As a result, it’s not accessible in the  
index view when it is initially loaded. How should I solve this  
problem?

I am not sure if I have expressed my question clearly. Any reply or  
comment is welcome.

Thanks!
