Ruby on rails Rails拆分的代码不工作

Ruby on rails Rails拆分的代码不工作,ruby-on-rails,ruby-on-rails-2,Ruby On Rails,Ruby On Rails 2,我使用的是rails 2.3。在我的应用程序中,它使用 val = Party.find(:all, :conditions => [" type in ('Physician') || id in (?)",PartyLabel.find(:all,:conditions=>"label_id=#{Label.find_by_label("Can Schedule").id}").collect{|p| p.party_id if Party.find(p.party_id).r

我使用的是rails 2.3。在我的应用程序中,它使用

val =  Party.find(:all, :conditions => [" type in ('Physician') || id in (?)",PartyLabel.find(:all,:conditions=>"label_id=#{Label.find_by_label("Can Schedule").id}").collect{|p| p.party_id if Party.find(p.party_id).respond_to?("provider_organizations")}], :with_disabled => true).select{|physician| not physician.provider_organizations.blank? }.collect{|enum| [enum.display_name_schedule, enum.id]}
代码实现了一些要求。现在我想把代码分成两部分

1. phys = Physician.find(:all, :include => :provider_organizations, :with_disabled => true).select{|physician| not physician.provider_organizations.blank? }.collect{|enum| [enum.display_name_schedule, enum.id]}
它工作得很好。。第二部分是

2. sch = Party.find(:all, :include => [:as_labels], :conditions => {:label => {:label => "Can Schedule"}}.respond_to?("provider_organizations")).select{|physician| not physician.provider_organizations.blank? }.collect{|enum| [enum.display_name_schedule, enum.id]}

它显示
NoMethodError(未定义的方法“提供者组织”用于#):
错误消息。。。如有任何意见,我们将不胜感激

看起来
respond\u to?(“提供者组织”)
是为错误的对象调用的。这是您的代码#2:

如果我理解正确,则
respond\u to?
应位于
select
中:

...
).select{ |physician|
  physician.respond_to?("provider_organizations") && not physician.provider_organizations.blank?
}.collect{ ...
...
).select{ |physician|
  physician.respond_to?("provider_organizations") && not physician.provider_organizations.blank?
}.collect{ ...