我要做的是编写一个方法,该方法将返回该模型的所有 outing_locations,它与它有一个 has_many 关系。
class Outing < ActiveRecord::Base
attr_accessible :description, :end_time, :start_time, :title, :user_id
belongs_to :user
has_many :outing_locations
has_many :outing_guests
has_one :time_range, :foreign_key => "element_id", :conditions => { :element_type => "outing" }
validates :title, :presence => true
validates :start_time, :presence => true # regex
validates :end_time, :presence => true # regex
def host_name
return User.find(self.user_id).full_name
end
end
我正试图让这个块特别工作。
还有另一个名为 OutingInvite 的模型,其中包含特定 Outing 的 id。我需要使用它来获取正确的郊游,然后拉出所述郊游的相关郊游地点。
这是一个粗略的示例:
<%@outing_invites.each do |invite|%>
...
<% @party = Outing.where(:id => invite.outing_id) %>
<% @party.outing_locations.each do |location| %>
然后让它输出每个位置。
但是,它说方法'outing_locations'不存在......