我在extJS中有两个多选择器(响应者组和jsut响应者)。错误的受访者有一个组(只有1个)。
在这里,我如何选择我的ids ..。
我得到respondent_group id,例如=1
respondent_ids = params[:selected_respondents].split(/,/).collect {|r| r.to_i}这里我得到了受访者的ids: 3,4,1
respondent_pure_ids = params[:selected_alone_respondents].split(/,/).collect {|r| r.to_i}在这里,我在组中找到了受访者(例如,我有10个组,每个组有1-3个受访者)。
respondents = Respondent.find(:all, :conditions => ["respondent_group_id in (?) AND id NOT IN (?)", respondent_ids, session[:user].id]) 我找到了回答者。
respondents_alone = Respondent.find(:all, :conditions => ["id in (?) AND id NOT IN (?)", respondent_pure_ids, session[:user].id]) 在这里我找到了受访者(我找到id,其中respondent_group = ?)然后给他们发邮件。
respondents.each do |r|
Notifier.deliver_inquiry_notification()
end我想要什么?我得到了respondents和respondents_alone的id。
For example respondents = 3 , 4 , 6
respondents_ alone = 3, 5, 6, 8我有3个和6个身份证都有。我不想混淆我的数据。如何检查:如果受访者if不等于respondent_alone if,我发送电子邮件,否则错误!
发布于 2011-07-15 19:43:58
您可以使用ruby数组算法来获取两个数组之间的差异,或者只获取一次每个条目:
a = [3, 4, 6]
b = [3, 5, 6, 8]
a - b # [4] (only a without any element of b, difference)
b - a # [5, 8] (only b without any element of a, difference)
a | b # [3, 4, 6, 5, 8] (complete set of all ids, union)
a & b # [3, 6] (ids same in both arrays, intersection)使用此选项,您可以检查某些is是只在一个数组中,还是同时在两个数组中,例如difference is empty或a|b==a&b =>两者都相等
请参阅http://www.ruby-doc.org/core/classes/Array.html
https://stackoverflow.com/questions/6705933
复制相似问题