In listing 11.36 of Michael Hartl’s superb tutorial, changes the unfollow form to use AJAX, but I keep getting the following error when I click on the “Unfollow” button:
ActionView::Template::Error (undefined method `model_name' for NilClass:Class):
The form, however, does work. If I click “Unfollow” I unfollow the currently displayed user. So it seems that @user in the form declaration is valid when the form is submitted:
<%= form_for(current_user.relationships.find_by_followed_id(@user),
html: { method: :delete },
remote: true) do |f| %>
but perhaps it’s no longer available when the “Follow” form tries to load?
I’ve tried at length to track this down but I can’t figure it out, and I haven’t seen anyone else post the same issue.
Any clues?
Thanks.
Agh … Dumb error.
I had copied the code for app/views/relationships/create.js.erb into app/views/relationships/destroy.js.erb as well. Copy-and-paste error.
Sorry for the false alarm. Thanks for your time.