Ruby on rails 轨道3。如何从分组的\u集合\u选择中排除记录?

Ruby on rails 轨道3。如何从分组的\u集合\u选择中排除记录?,ruby-on-rails,ruby,Ruby On Rails,Ruby,我有一张表格记录教员的报酬。付款记录在费用表中。我有以下工作条件: <%= f.grouped_collection_select :scheduled_session_id, User.where(:role => 'instructor'), :scheduled_sessions, :full_name, :id, :identifier_with_cost, :include_blank => true %> 但我想排除已经支付的会话。scheduled_ses

我有一张表格记录教员的报酬。付款记录在费用表中。我有以下工作条件:

<%= f.grouped_collection_select :scheduled_session_id, User.where(:role => 'instructor'), :scheduled_sessions, :full_name, :id, :identifier_with_cost, :include_blank => true %>
但我想排除已经支付的会话。scheduled_sessions表有一个名为“paid”的布尔列


我可以使用
ScheduledSession.where(paid:[false,nil])
进行查询,但是如何在分组的集合上实现它呢

仔细查看文档后,(你知道在编码一段时间后大脑无法处理很多信息,这就是我本周实施pomodoro技术的原因):
grouped\u collection\u select(object,method,collection,group\u method,group\u label\u method,option\u key\u method,option\u value\u method,options={},html_options={})public
,它是一个组方法,提供子记录列表

因此,为了提出这个解决方案,我暂时忽略了费用模型。我现在只关心用户和ScheduledSession模型,因为这将生成我的选择菜单。我在父模型中创建了一个方法:

class User < ActiveRecord::Base
has_many :scheduled_sessions, :foreign_key => 'instructor_id'

def not_paid_scheduled_sessions
   ScheduledSession.where(:instructor_id => self.id).where(paid: [false, nil])
 end
我用

f.grouped_collection_select :scheduled_session_id, User.where(:role => 'instructor'), :not_paid_scheduled_sessions, :full_name, :id, :identifier_with_cost 
希望它也能帮助别人

f.grouped_collection_select :scheduled_session_id, User.where(:role => 'instructor'), :scheduled_sessions, :full_name, :id, :identifier_with_cost, :include_blank => true
f.grouped_collection_select :scheduled_session_id, User.where(:role => 'instructor'), :not_paid_scheduled_sessions, :full_name, :id, :identifier_with_cost