Ajax, javascript_tag and JS Var trouble, help nedded

Hello there,

I have a clients controller, and I want it to respond both ajax and html
to the new action.

If the user uses the html action, the new partial is going to be
rendered and all works with no problem.
In oder hand, if a ajax request is submitted, everything renders ok (it
will be rendered inside a div in the index page), but some JS functions

I have this piece of code in my view:

<% templates = “var phone_template=’#{generate_template(contact_form,
:phones, :partial => “/contacts/phones/create”)}’” -%>
<%= javascript_tag(templates) -%>

What will generate a script tag in the html file (if is called normally,
html request), or the result is passed to the page (using ajax), and it
can be visualized using firebug.

This code (in the same view, on the botton):
<%= link_to ‘Adicionar Telefone’, ‘#phone_template’, :class =>
“add_nested_item”, :rel => “contact_phones” %>
Calls a function (evnt: onclick, function: add_nested_item) that is
declared in the application.js file.

I have narrow the error down, and I thing that (pretty sure) that the
function “add_nested_itme” cant find the js var “phone_template”.

What can be done to solve this problem.


David S.

Ps: Any extra code will be given if needed.

Application.js => http://pastie.org/555701
Partial (view) => http://pastie.org/555708
Result of javascript_tag => http://pastie.org/555714

I have not solved my problem yet.

When the var ( that was sent by ajax ) arrives, it looks like that it
get evaluated, but the function can’t find it.

Any ideas?

David S.

Problem is solved.

<% templates = “var phone_template=’#{generate_template(contact_form,
:phones, :partial => “/contacts/phones/create”)}’” -%>
<%= javascript_tag(templates) -%>

I have removed the key “var” to make it global, so functions of other
scopes could see it.

David S.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs