Posts Tagged 'forms'

MongoMapper 0.7.0: ids created on new()

I upgraded to MongoMapper 0.7.0 the other day and found that an XHR form was no longer working. It turns out that as of this version, MM now generates an id on new(). I think this is a great idea (think about building associations–you don’t need to save first with pregenerated ids), but when used with form_for() the generated form id is no longer new_model, but model_<id>. Because the MM object responds to new_record? (alias of new?), form_for() handles the rest of this correctly. If you want to keep the new_record style id in the form, you can manually set :id on the form, or you can just set the id on the object to nil: YourModel.new(:id => nil).


Pages

Categories

Copyright ©2008-2013 James E Orchard-Hays, All Rights Reserved