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

Need some help here guys plz

On Jun 14, 6:58 am, Bruno S. [email protected]
wrote:

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

@usuarios is nil when you post the forms and there are validation
errors (you’re not reloading them a the create action), here’s how to
solve it:

<%=collection_select(:usuario, :id, Usuario.all, :id, :nome_completo)%>

Maurício Linhares
http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr

On Sun, Jun 14, 2009 at 2:58 AM, Bruno

thanks!
I got it working like this:
http://disciplinas.dcc.ufba.br/svn/MATA76/Trabalho20091/equipe13/trunk/lac/app/views/vendas/_form.html.erb?view=log

The problem is with nested models through ajax. When submit button is
hitted, it claims that I didn’t choose a credit card(cartao_de_credito)
for the payment(pagamento). How come?
http://disciplinas.dcc.ufba.br/svn/MATA76/Trabalho20091/equipe13/trunk/lac/app/views/vendas/_pagamento.html.erb?view=log

you can browse all the code through svn pages

Nice!
It worked.
Last thing is that I tried using select_tag in many ways, but none
worked.
By lines 9-12 in
http://disciplinas.dcc.ufba.br/svn/MATA76/Trabalho20091/equipe13/trunk/lac/app/views/vendas/_pagamento.html.erb?view=log
I just want a normal select tag with those 4 values.

Frederick C. wrote:

On Jun 14, 2:57�pm, Bruno S. [email protected]
wrote:

thanks!
I got it working like this:http://disciplinas.dcc.ufba.br/svn/MATA76/Trabalho20091/equipe13/trun…

The problem is with nested models through ajax. When submit button is
hitted, it claims that I didn’t choose a credit card(cartao_de_credito)
for the payment(pagamento). How come?http://disciplinas.dcc.ufba.br/svn/MATA76/Trabalho20091/equipe13/trun…

You’re using collection_select wrong. EIther you use the form_builder
version and do

f.collection_select :attribute_name, …

or you use the old version:

collection_select :ivar_name, :attribute_name, …

but not some mix of the two as you have there

Fred

On Jun 14, 2:57 pm, Bruno S. [email protected]
wrote:

thanks!
I got it working like this:http://disciplinas.dcc.ufba.br/svn/MATA76/Trabalho20091/equipe13/trun…

The problem is with nested models through ajax. When submit button is
hitted, it claims that I didn’t choose a credit card(cartao_de_credito)
for the payment(pagamento). How come?http://disciplinas.dcc.ufba.br/svn/MATA76/Trabalho20091/equipe13/trun…

You’re using collection_select wrong. EIther you use the form_builder
version and do

f.collection_select :attribute_name, …

or you use the old version:

collection_select :ivar_name, :attribute_name, …

but not some mix of the two as you have there

Fred