我正在使用宝石https://github.com/dsaronin/milia。我的模型之一称为组:
class Group < ActiveRecord::Base
#.....
acts_as_tenant
end
但由于某种原因,我无法创建它。这是rails控制台:
t = Tenant.create(cname: 'cname1', company: 'comp1')
=> #<Tenant id: 3, tenant_id: nil, cname: "cname1", company: "comp1", created_at: "2015-03-03 03:39:38", updated_at: "2015-03-03 03:39:38">
[33] pry(#<Cucumber::Rails::World>)> t.valid?
=> true
[34] pry(#<Cucumber::Rails::World>)> t.new_record?
=> false
[35] pry(#<Cucumber::Rails::World>)> t.errors
=> #<ActiveModel::Errors:0x00000108a5e6d8
@base=
#<Tenant id: 3, tenant_id: nil, cname: "cname1", company: "comp1", created_at: "2015-03-03 03:39:38", updated_at: "2015-03-03 03:39:38">,
@messages={}>
但是当涉及到 Group 时,它总是无效的:
> g = Group.new(name: 'name1')
=> #<Group id: nil, name: "name1", room: nil, person_id: nil, created_at: nil, updated_at: nil, tenant_id: nil>
[37] pry(#<Cucumber::Rails::World>)> g.tenant
=> nil
[38] pry(#<Cucumber::Rails::World>)> g.tenant = t
=> #<Tenant id: 3, tenant_id: nil, cname: "cname1", company: "comp1", created_at: "2015-03-03 03:39:38", updated_at: "2015-03-03 03:39:38">
[39] pry(#<Cucumber::Rails::World>)> g.save!
ActiveRecord::RecordInvalid: Gültigkeitsprüfung ist fehlgeschlagen: Tenant muss ausgefüllt werden
from /Users/alex/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.21/lib/active_record/validations.rb:56:in `save!'
[40] pry(#<Cucumber::Rails::World>)> g.errors
=> #<ActiveModel::Errors:0x00000108888ea8
@base=
#<Group id: nil, name: "name1", room: nil, person_id: nil, created_at: nil, updated_at: nil, tenant_id: nil>,
@messages={:tenant_id=>["muss ausgefüllt werden"]}>
[41] pry(#<Cucumber::Rails::World>)> g.valid?
=> false
[42] pry(#<Cucumber::Rails::World>)> g.new_record?
=> true
怎么了?