October 17

0 comments

Ruby on Rails – Deleting a value from an array

By Christopher Mendla

October 17, 2016


Last Updated on November 30, 2019 by Christopher G Mendla

I needed to remove users who were already assigned from a drop down list for assignments. This did the trick. 

# ——————- new ——————————# We want to show a list of people that the user can assign a complaint to. However, we do not want to send# to people who have already been assigned to the complaint. So# 1. Pluck the user names from the User table using unique# 2. Pull the histories that match the complaint ID and put them in @existing_sent_to This should be a small list# 3. Go through the existing_sent_to and use @users.delete to remove the sent to name from the @users

def new @history History.new
@
users User.uniq.pluck(:name) @existing_sent_to History.where(:complaint_id => 

           $document_assign)
  @existing_sent_to.each do |remove_existing|
    @users.delete(remove_existing.sent_to)
end

end end

Christopher Mendla

About the author

Leave a Reply

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}