I have 2 multi selectors in extJS (respondents groups and jsut respondents). Erery respondent have a group (ONLY 1).
here, how i selected my ids …
I get respondent_group id, for example = 1
respondent_ids = params[:selected_respondents].split(/,/).collect {|r| r.to_i}
here i get respondents ids: 3,4,1
respondent_pure_ids = params[:selected_alone_respondents].split(/,/).collect {|r| r.to_i}
here i find respondents in group (for example i have 10 groups, every group has 1-3 respondents).
respondents = Respondent.find(:all, :conditions => ["respondent_group_id in (?) AND id NOT IN (?)", respondent_ids, session[:user].id])
I find respondents .
respondents_alone = Respondent.find(:all, :conditions => ["id in (?) AND id NOT IN (?)", respondent_pure_ids, session[:user].id])
here i found respondents (i find id where respondent_group = ?) and send them email.
respondents.each do |r|
Notifier.deliver_inquiry_notification()
end
What I want?
I get respondents and respondents_alone id’s.
For example respondents = 3 , 4 , 6
respondents_ alone = 3, 5, 6, 8
I have 3 and 6 ids in both. I dont want to dublicate my data . How to check: if respondents ids DOES NOT equals respondent_alone ids I SEND EMAIL else error!
You can use ruby array arithmetic to get the difference between both arrays or to get every entry only once:
With this you can check if some ids are only in one array or in both, e.g. difference is empty or
a|b==a&b=> both are equalcf. http://www.ruby-doc.org/core/classes/Array.html