我在我的rails 4迁移中使用t.text :emails, array: true, default: [], null:false
来发送电子邮件给记者。我在那里使用以下代码验证每个条目
validates_each :emails do |record, attr, value|
value.each do |email|
record.errors.add attr, I18n.t('reporter.error.not_valid_email', email: email) if (email =~ EMAIL_VALIDATION_REGEXP) == nil
end
end
当我创建AM类的实例
时,我收到以下错误 1) Reporter budget, receipt and member interaction testing the remaining_promise_for_whole_budget_title method for overview of all available budgets
Failure/Error: @reporter = FactoryGirl.create(:reporter)
NoMethodError:
undefined method `each' for "[\"lkajsdf@gmail.com\"]":String
# ./app/models/reporter.rb:6:in `block in <class:Reporter>'
# /Users/malik/.rvm/gems/ruby-2.2.1@maalify/gems/activemodel-4.2.0/lib/active_model/validator.rb:179:in `call'
这是我工厂女孩的定义
FactoryGirl.define do
factory :reporter do
name "MyReport"
donations %W(1 2)
tanzeems "MyString"
interval "28"
emails ["lkajsdf@gmail.com"]
end
end
答案 0 :(得分:0)
FactoryGirl.define do
factory :reporter do
name "MyReport"
donations %W(1 2)
tanzeems "MyString"
interval "28"
emails { ["lkajsdf@gmail.com"] }
end
end
这是解决方案。让它在街区。