On 03 Dec 2011, at 17:22, Dani Dani wrote:
how can I make sure that 'customer_student' won't be pushed twice to
the
hash in the following example ?
@potential_course_students = []
@selected_customers.each do |customer|
customer.customer_student.each do |customer_student|
if customer_student.display_name.include?(params[:term]) &&
! @potential_course_students.include?(customer_student)
@potential_course_attendees << customer_student
end
end
end unless params[:term].blank?
Since you're pushing objects into an array, you can just "uniq!" it:
http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-uniq-21
I do have to add that you're doing a lot in the controller that seems
to be model-related. You might want to encapsulate functionality a bit
better.
Best regards
Peter De Berdt
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.