Partials views and instance variables go nil

Hi everyone!

Model:http://pastie.org/511290 Controller:http://pastie.org/511285 View new:http://pastie.org/511286 View _form:http://pastie.org/511284

When I hit submit button there's an error for usuarios(users in portuguese) instance. It does not seems to save usuarios even though it seems to be posted by the form. Error:http://pastie.org/511292

Well the error happens because a validation fails and so it rerenders the form, however your create action doesn't setup @usuarios and so the bit where you call collection_select fails.

If you look at your parameters although the id is being submitted, it's not being submitted in the right place in your params hash: you've got :usario => {:id => '6'}, whereas what you want is :venda => {:usario_id => '6', ... }

This is because of how you are using collection_select: you're telling it that you are editing the id property of @usuario, but you're not: you're editing the usario_id property of @venda. Fix that and it should work (why not call collection_select on the form builder object ?)

Fred