Class Actual is managing the creation and deletion of objects in class Friendgroup. The form page

<ul id=friendgroups>   <%= render @friendgroups %> </ul>

<%= form_with model: Friendgroup.new, data: {'js-friendgroup-form' => true} do |form| %>   
  Name <%= form.text_field :name %>
  <%= form.submit %> 
<% end %>

calls the collection of friendgroups properly on page load, the controller for friendgroups does create records:

  def create
    params[:friendgroup][:user_id] = current_user.id
    @friendgroup = Friendgroup.new(friendgroup_params)
    authorize @friendgroup
    if @friendgroup.save
      render partial: 'friendgroup', locals: {friendgroup: @friendgroup}
    end  
  end

On page load, existing objects are loaded:

<li data-js-friendgroup-id=<%= friendgroup.id %>>
  <%= friendgroup.name %> <%= link_to "Delete", friendgroup, remote: true, method: :delete, data: { confirm: "Are you sure you want to delete '#{friendgroup.name}'?" } %>

However, the AJAX actions are not percolating back to the index, leading me to conclude that the javascript functions are no binding to the proper classes/items:

//= require jquery3
//= require jquery-ui
//= require rails-ujs
$(document).ready(function() {
  $('[data-js-friendgroup-form]').on("ajax:success", function(event, data, status, xhr){
    var friendgroup = $(xhr.responseText).hide();
    $('#friendgroups').append(friendgroups);
    friendgroup.fadeIn(1000);
//    $('#friendgroups').append(xhr.responseText);
  });

  $('[data-js-friendgroup-id]').on("ajax:success", function(event, data, status, xhr){
    var friendgroup_id = xhr.responseJSON.id;
    $('[data-js-friendgroup-id=' + friendgroup_id + ']').hide();
  });
});

Another possible culprit is the console error TypeError: url.indexOf is not a function being activated by jQuery3, but that has little to do with the above code.

How can these cross model actions run properly?

1 Answers

0
user2965549 On

bad eyes question

    $('#friendgroups').append(friendgroup);

instead of

    $('#friendgroups').append(friendgroups);