views:

26

answers:

2

Hi folks, i do not quite understand what is wrong with my code - it is even causing my server to hang up.

What i need to do is for the controller to return a JS script that when executed, will append a rendered partial to my $(".reviews")

# test.html.erb
$.getScript("/test");

# controller
  wants.js do
    render :partial => "/shared/activity"
  end

#/shared/activity.js.erb
$("#reviews").append("<%= escape_javascript(render(:partial => /shared/activity )) %>");

I suspect there is something wrong with the way i am asking for the render in my controller. In fact, it throws up all sorts of weird errors.

+2  A: 

You call yourself in your partial. So you have an infinite loop.

shingara
What would be the right way to do it? I am puzzled- i cannot find good examples in the rails docs
ming yeow
What you want? There are no output in your partial.
shingara
Sorry for confusion. I want the controller to render the activity.js.erb, which in turns return /shared/activity.HTML.erb.
ming yeow
I need the "/shared/activity.js.erb" to render "/shared/activity.html.erb". I have updated the question to reflect that I need to run javascript code in the js file, in order to render a html partial in my main file
ming yeow
+1  A: 

Since you have both activity.js.erb and activity.html.erb, it will probably help if you specify which one you want to render:

# test.html.erb
$.getScript("/test");

# controller
wants.js do
  render :partial => "/shared/activity.js.erb"
end

#/shared/activity.js.erb
$("#reviews").append("<%= escape_javascript(render(:partial => '/shared/activity.html.erb' )) %>");
captaintokyo
thanks captain, that works! =D
ming yeow