ruby on rails - Join the associated object into the belongs_to object -
i have event
model has many dateentry
because event can have multiple datetimes.
i have view see events date entries specific day. i've made class method in models/event.rb:
def self.by_date(date) includes(:date_entries) .where(date_entries: { begins_at: date.beginning_of_day..date.end_of_day }) end
and works fine.
now on view loop on events grabbed query:
@events.each |event| # whatever
i looking way use date selected dateentry in loop. think have use activerecords joins
method, have tried in many ways , when not getting error output still same.
for clarifying, want in loop event.selected_date_entry_by_the_by_date_method.begins_at
or that.
first, in example date events same. set @date
in controller , use in views.
second, seems should doing things other way around. instead of finding events should finding dateentries , iterating on those.
Comments
Post a Comment