lundi 2 mars 2015

Unable to create a simple model instance with acts_as_tenant

I'm using a gem http://ift.tt/MTcrec. One of my models is called Group:



class Group < ActiveRecord::Base
#.....

acts_as_tenant
end


But I can't create it for some reason. Here's rails console:



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={}>


But when it comes to Group, it's always invalid:



> 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


What's up with it?


Aucun commentaire:

Enregistrer un commentaire