I am trying to filter out some objects in an array by using the include? method, but I keep running into this error undefined method 'include?' for #<Trip:0xa01b7b0>.
I basically have two models, eventdeal and trip. I created a 3rd relationship model, eventdealtrip, that ties the two models together.
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 !@trips.blank? %>
<% @trips.each do |trip| %>
<% if !trip.include?(@eventdeal) %>
<!--Content-->
<% end %>
<% end %>
<% end %>
Basically, I only want to display the trips that do NOT include the current eventdeal (which is defined in the controller).
Any insight as to why I’m getting the undefined method error?
Thanks.
The include? method is usually for arrays, try this: