event
特定の日付に発生するかどうかを確認するクエリを作成するのに助けが必要です。
has_manyにevent
は、アクセスしようとしているという属性がありますが、アクセスできないようです。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'
エラーが発生します。
ありがとう!