0

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 %>
2
  • that error is caused by this line current_user.relationships.find_by_followed_id(@player). Do you have @player declared in the create action? Commented Mar 4, 2013 at 11:32
  • You were right, I made a mistake, I declared @user. Commented Mar 4, 2013 at 11:35

1 Answer 1

1
$("#follow_form").html("<%= escape_javascript(render('players/follow')).html_safe %>")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer, but it still doesn't work, and an error is displayed. I'll edit my post.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.