我的Rails 5應用程序有一個列scheduled_at(datetime
)的模型。在我的表單中我有場schedule_date和使用attr_accessor
schedule_time:加入日期和時間在模型中的日期時間Rails 5
attr_accessor :schedule_date, :schedule_time
現在,當有人提出,形式我想加盟東星兩個字段並設置scheduled_at
領域。這之後,我也想運行我對scheduled_at
驗證我試圖把這個在我的模型:
attr_accessor :schedule_date, :schedule_time
scheduled_at = schedule_date + ' ' + schedule_time
# Validations
validate :validate_scheduled_at
def validate_scheduled_at
# Custom validation for
end
但是,這告訴我:
未定義的局部變量或方法`schedule_date」
在你的模型中,你把這個代碼放在哪裏? – MurifoX
我已更新我的問題。 – almo
此代碼'scheduled_at = schedule_date +''+ schedule_time',不在'validate_scheduled_at'方法內嗎? – MurifoX