Ruby on rails 4 在factory gril中定义数组时出现错误
我在a reporter中的rails 4电子邮件迁移中使用了Ruby on rails 4 在factory gril中定义数组时出现错误,ruby-on-rails-4,testing,rspec,factory-bot,Ruby On Rails 4,Testing,Rspec,Factory Bot,我在a reporter中的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: e
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'
这是解决办法。让它在块中。Stll获取
失败/错误:ap@reporter.valid?NoMethodError:未定义“[\”的方法“each”lkajsdf@gmail.com\“]”:字符串
FactoryGirl.define do
factory :reporter do
name "MyReport"
donations %W(1 2)
tanzeems "MyString"
interval "28"
emails ["lkajsdf@gmail.com"]
end
end
FactoryGirl.define do
factory :reporter do
name "MyReport"
donations %W(1 2)
tanzeems "MyString"
interval "28"
emails { ["lkajsdf@gmail.com"] }
end
end