Rails 3 AJAX Follow Button Various Controllers

I have a Rails 3 app with a follow / unfollow button.

Forms _follow.html.erb

and _unfollow.html.erb

are in the controller A

. The controller B

has actual create and destroy methods (this is the center of the relationship has_many :through

). Therefore, create.js.erb

and destroy.js.erb

associated with consistency and unfollow, they are in the folder manager B


The AJAX code looks like this: $("#followform").html("<%= escape_javascript(render 'A/follow') %>")

The code works when I replace render A/follow

with something like <p>Testing</p>

, but cannot display the partial with the above code.

Can't you render views from external controllers? I have checked the Rails Guide and they seem to suggest that this is the case. So, does anyone know the problem here?

Any help is greatly appreciated !!!


source to share

1 answer

It looks like the problem is that your partial files are not getting all the information they need, as you have an instance variable in the partial that is not set, or perhaps a local variable.

Check all the variables that are in your part and make sure they are set somewhere in the chain.

If you post your actual controller action that serves both the partial and the partial code itself, we can probably help more.



All Articles