The following tag in a nested form
<%= check_box_tag "friend_ids[]", ff.id, @contentrestrictions.friends.include?(ff.id) %>
is handling the following array of records
>> @contentrestrictions
[
#<Contentrestriction id: 29, usercontent_id: nil, friend_id: nil, created_at: "2019-04-28 10:55:32", updated_at: "2019-04-28 10:55:32">,
#<Contentrestriction id: 30, usercontent_id: nil, friend_id: 2, created_at: "2019-04-28 10:55:32", updated_at: "2019-04-28 10:55:32">,
#<Contentrestriction id: 31, usercontent_id: nil, friend_id: 4, created_at: "2019-04-28 10:55:32", updated_at: "2019-04-28 10:55:32">]
Even though
class Contentrestriction < ApplicationRecord
belongs_to :friend, optional: true
@contentrestrictions. followed by any of friend_id, friend_ids both appended with or without [] all lead to NoMethodError: undefined method for Array.
how can this include function get a proper array to work with?
<%= check_box_tag "friend_ids[]", ff.id, @contentrestrictions.pluck(:friend_id).include?(ff.id) %>. Consider asign@contentrestrictions.pluck(:friend_id)to a variable if used more than one time in the template.pluckall the time, but it did not dawn on me here!