私がやろうとしているのは、has_many関係を持つこのモデルのouting_locationsのすべてを返すメソッドを作成することです。
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'が存在しないと言っています...