ruby on rails - nil is not a symbol accepts_nested_attributes_for has_one association -
i trying accepts_nested_attributes_for
working has_one
association. have following set using mongoid.
class foo include mongoid::document include mongoid::timestamps include mongoid::paranoia has_and_belongs_to_many :bars, inverse_of: nil end class bar include mongoid::document include mongoid::paranoia has_one :magazine, class_name: 'foo', dependent: :destroy, inverse_of: nil accepts_nested_attributes_for :magazine end
when following in rails console seem following output.
r = bar.new => #<bar _id: 1213 .... [2] pry(main)> r.foo.build typeerror: nil not symbol /users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems /mongoid-3.1.6/lib/mongoid/attributes.rb:155:in `respond_to?
this blog post writeup of inverse_of
. instead of inverse_of: nil
in models, have specify symbol. example, :bars
association should declared inverse_of: :magazine
.
Comments
Post a Comment