我想通過使用include過濾出數組中的一些對象?方法,但我一直遇到這個錯誤undefined method 'include?' for #<Trip:0xa01b7b0>
。未定義的方法`include?'關係模型
我基本上有兩個模型,eventdeal和trip。我創建了第三個關係模型eventdealtrip,它將兩個模型聯繫在一起。
trip.rb
class Trip < ActiveRecord::Base
has_many :eventdealtrips, :dependent => :destroy
has_many :eventdeals, :through => :eventdealtrips
end
eventdeal.rb
class Eventdeal < ActiveRecord::Base
has_many :eventdealtrips
has_many :trips, :through => :eventdealtrips, :dependent => :destroy
end
eventdealtrip.rb
class Eventdealtrip < ActiveRecord::Base
belongs_to :eventdeal
belongs_to :trip
end
eventdealtrips/new.html.erb
<% if [email protected]? %>
<% @trips.each do |trip| %>
<% if !trip.include?(@eventdeal) %>
<!--Content-->
<% end %>
<% end %>
<% end %>
基本上,我只想顯示不包含當前eventdeal(在控制器中定義)的行程。
任何洞察力爲什麼我得到未定義的方法錯誤?
謝謝。
謝謝,我忘了eventdeals。 – Huy