0
我驗證父的子對象是這樣的:我可以從參數名稱中獲得成員的符號嗎?
validate :overdue_tasks_valid
validate :created_overdue_tasks_valid
我再有這樣的方法:
private
def overdue_tasks_valid
validate_notification(overdue_tasks, :overdue_tasks)
end
def created_overdue_tasks_valid
validate_notification(created_overdue_tasks, :created_overdue_tasks)
end
def validate_notification(notification, key)
return if notification.valid?
notification.errors.full_messages.each do |message|
errors.add key, message
end
end
我想知道的是,我可以只傳遞一個參數validate_notfication並以某種方式確定方法中的符號?
所以確認通知將被稱爲像這樣:
validate_notification(overdue_tasks)
而且該方法是這樣的:
def validate_notification(notification)
return if notification.valid?
notification.errors.full_messages.each do |message|
errors.add [SOMEHOW GET THE SYMBOL], message
end
end