I'm using this gem for my forms :
https://github.com/plataformatec/simple_form
I have 3 input fields each for day, month, year :
= f.input :dob_day, label_html: {style: 'display:none'}, placeholder: 'DD'
= f.input :dob_month, label_html: {style: 'display:none'}, placeholder: 'MM'
= f.input :dob_year, label_html: {style: 'display:none'}, placeholder: 'YYYY'
In my model (important bit) I'm trying to build a validations for the date of birth :
class User < ActiveRecord::Base
attr_writer :dob_day, :dob_month, :dob_year
def dob_day
@dob_day
end
def dob_month
@dob_month
end
def dob_year
@dob_year
end
user.validates :dob_day, presence: true
user.validates :dob_month, presence: true
user.validates :dob_year, presence: true
user.validates :dob, presence: true,
date: { before: Proc.new { Time.now - 18.years }, message: ": You must be over 18 to join" }
Right now I get the error :
Can't mass-assign protected attributes: dob_day, dob_month, dob_year
I'd like to inject dob field with values from dob_day, dob_month, dob_year. I'd do it in model if possible rather than in controller
Am I doing this the wrong way? This should be fairly simple, but turns out its not
as: :date, start_year: Date.today.year - 90, end_year: Date.today.year - 18, order: [:month, :year, :day]
– Nitin Jain