1

Solved this:

I have a following situation:

I have Graph and Node model.

While on graph/show.html.erb I make an ajax post with an id of a Node:

   var val = document.getElementById('nodeName').value;
  if(val){
  $.post("/nodes/this_node/", {id:val});    
  console.log(val);
   }

How do I get that Node to render on the same page in, for example, ?

EDIT:: I have a custom POST action in node_controller :

def this_node
   @node = Node.find(idd)
  respond_to do |format|
     format.js   
  end
end

I had to add app/views/nodes/this_node.js.erb with:

  $("#node_div").html('<%= escape_javascript(render :partial => "node_content", :locals => { :node => @node}) %>');

and a partial in views/nodes/_node_content.html.erb

  <%= @node.content %>

All works.

EDIT: Actually fixed it (above code works)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.