The domain name is static so it will always be the same. Its not like a magic number that could so I need to right a regex or use something in rails that can validate that domain = “domain.com” or whatever I put there…
I have been playing with:
validates_each :email |record, attr, value|
record.errors.add attr 'bad domain' unless /ravennainteractive.com$/ =~ value
end
that doesn’t work…
thanks so much for your help.
Edit 1/9/12
So after looking closer at the rails guides, I modified what I had with what Vivek said and here is what I am using:
validates_each :email do |record, attr, value|
record.errors.add(attr, 'You must use an ravennainteractive.com email address') unless value =~ /ravennainteractive.com$/
end
this is accepting invalid values: (from the log) “approvals_attributes”=>{“0″=>{“email”=>”tj@4thavenuemedia.com”}}}, “commit”=>”Save”}
I should also note that this is validating on a nested form. This is a Recommendation#new form with a fields_for…
any other ideas?
I am not sure it this helps, but shouldn’t the value match the expression?
Shouldn’t it be
unless value =~ /ravennainteractive.com$/?