0
특정 날짜에 event
이 발생하는지 확인하는 쿼리를 작성하는 데 도움이 필요합니다.has_many 관계에서 자식 특성 가져 오기
event
has_many days
및 day
내가 접근을 시도하고있다 :date
이라는 속성을 가지고 있지만 그것을 얻을 수없는 것.
코드 : 내보기에서
class Event < ActiveRecord::Base
attr_accessible :title, :days_attributes
has_many :days
accepts_nested_attributes_for :days
scope :occurs_on, lambda {|date| where(Day.first.date => date)}
end
class Day < ActiveRecord::Base
attr_accessible :date, :event_id
belongs_to :event
validates :date, presence: true
end
class EventsController < ApplicationController
def index
@events = Event.occurs_on(Date.today)
end
end
내가 이런 식으로 날짜를 표시 할 수는 : <%= event.days.first.date.strftime("%A, %B %e") %>
그래서 나는 내 모델에서 일 거라고 생각하지만 그렇지 않습니다. undefined method 'to_sym'
오류가 발생합니다.
감사합니다. 내가 제대로 질문을 읽고 있어요 경우