<commit_before>class Admin::FamilyRelationshipsController < AdminController
  def new
    @family_relationship = FamilyRelationship.new(friend_id: friend.id)
    render_modal
  end

  def create
    @family_relationship = FamilyRelationship.create(family_relationship_params)
    if @family_relationship.persisted?
      render_list
    else
      # TO DO, fix population of relation dropdown and set error on base
      render_modal
    end
  end

  def destroy
    @family_relationship ||= FamilyRelationship.find(params[:id])
    if @family_relationship.destroy
      # TO DO flash message
    else
      # TO DO flash message
    end
    render_list
  end

  private

  def render_modal
    respond_to do |format|
      format.js do
        render file: 'admin/friends/family_relationships/modal',
          locals: { friend: friend, family_relationship: @family_relationship }
      end
    end
  end

  def render_list
    respond_to do |format|
      format.js do
        render file: 'admin/friends/family_relationships/list', locals: { friend: friend }
      end
    end
  end

  def friend
    @friend ||= current_community.friends.find(params[:friend_id])
  end

  def family_relationship_params
    params.require(:family_relationship).permit(
      :relation_id,
      :relationship_type,
      :reciprocal_relationship_id
    ).merge(friend_id: friend.id)
  end
end
<commit_msg>add a flash message if family_relationship destroy is NOT successful<commit_after>class Admin::FamilyRelationshipsController < AdminController
  def new
    @family_relationship = FamilyRelationship.new(friend_id: friend.id)
    render_modal
  end

  def create
    @family_relationship = FamilyRelationship.create(family_relationship_params)
    if @family_relationship.persisted?
      render_list
    else
      render_modal
    end
  end

  def destroy
    @family_relationship ||= FamilyRelationship.find(params[:id])
    unless @family_relationship.destroy
      flash[:error] = 'There was an issue removing this family relationship.'
    end
    render_list
  end

  private

  def render_modal
    respond_to do |format|
      format.js do
        render file: 'admin/friends/family_relationships/modal',
          locals: { friend: friend, family_relationship: @family_relationship }
      end
    end
  end

  def render_list
    respond_to do |format|
      format.js do
        render file: 'admin/friends/family_relationships/list', locals: { friend: friend }
      end
    end
  end

  def friend
    @friend ||= current_community.friends.find(params[:friend_id])
  end

  def family_relationship_params
    params.require(:family_relationship).permit(
      :relation_id,
      :relationship_type,
      :reciprocal_relationship_id
    ).merge(friend_id: friend.id)
  end
end

{'fraction_non_alphanumeric': 0.07006827164929932, 'fraction_numerical': 0.0, 'mean_word_length': 3.2118003025718607, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '527777', 'n_tokens_mistral': 836, 'n_tokens_neox': 779, 'n_words': 199}