I have a _follow_form partial :
<% unless current_user == @player %>
<div id="follow_form">
<% if current_user.following?(@player) %>
<%= render 'unfollow' %>
<% else %>
<%= render 'follow' %>
<% end %>
</div>
<% end %>
My _follow partial looks like this :
<%= form_for current_user.relationships.build(:followed_id => @player.id),
:remote => true do |f| %>
<div><%= f.hidden_field :followed_id %></div>
<div class="actions"><%= f.submit "Follow" %></div>
<% end %>
My create.js.erb file :
$("#follow_form").update("<%= escape_javascript(render('players/follow')) %>")
But nothing happens when I create a Relationship. I mean the relation is created, but the partial doesn't update. When I try with :
$("#follow_form").append("foobar");
It works.
How could I update #follow_form ? Thanks for your help.
PS: I searched for a solution before posting, but everything I tried failed.
UPDATE
With :
$("#follow_form").html("<%= escape_javascript(render('players/unfollow')).html_safe %>")
Nothing happens, the partial isn't replaced but an error occurs :
NoMethodError in Relationships#create
Showing C:/Ruby/ostriker/app/views/players/_unfollow.html.erb where line #1 raised:
undefined method `model_name' for NilClass:Class
My _unfollow partial :
<%= form_for current_user.relationships.find_by_followed_id(@player),
:html => { :method => :delete },
:remote => true do |f| %>
<div class="actions"><%= f.submit "Unfollow" %></div>
<% end %>
current_user.relationships.find_by_followed_id(@player). Do you have @player declared in the create action?