Update attributes of embedded new record in Rails & Mongoid -
i'm trying write piece of functionality creates record template in rails app, customisations user.
the difficulty comes when trying let user override field in embedded document: document duplicated rather updated.
i start object of type, let's say, externallinkgrouptemplate
, , contains number of externallink
s. it's used create externallinkgroup
contains externallink
s. user should able edit link text when it's cloned not url, user presented form when it's copied user should able can create copy of (simplified because of code in different files, remove tests success etc):
@link_group = externallinkgroup.new @template.links.each {|link| @new_link_group.links.push link.dup } @link_group.update_attributes(params[:link_group])
when link group created, contains twice many links template, , second set has changes. clearly, mongoid/activewhatever creating new items rather updating existing ones.
i don't want pass through fields in parameters without duplicating because there's inheritance going on , of links of different types , have fields, , don't want code partial each of them has bunch of hidden fields. also, don't want user able modify hidden fields , submit whatever.
i can't reference them _id
because they're not saved yet. expecting array index of template[links_attributes]
sufficient it's not.
what do?
using rails 3.2.13, mongodb 2.2.x, mongoid 3.0.5.
Comments
Post a Comment