I have a form where I edit a model and all its associated models in a
has_many relation:
<%= error_messages_for ''roteiro'' %>
<!--[form:roteiro]-->
<p><label
for="roteiro_titulo">Titulo</label><br/>
<%= text_field ''roteiro'', ''titulo'', {
:size => 50 } %></p>
<table>
<% @roteiro.roteiro_tipos.each do |tipo| -%>
<% @tipo = tipo -%>
<%= error_messages_for ''tipo'' %>
<tr>
<td><%= text_field ''tipo[]'',
''titulo'' %></td>
<td><%= text_field ''tipo[]'',
''preco'' %></td>
</tr>
<% end %>
</table>
My update method is this:
def update
@roteiro = Roteiro.find(params[:id])
if @roteiro.update_attributes(params[:roteiro]) and
RoteiroTipo.update(params[:tipo].keys, params[:tipo].values)
flash[:notice] = ''Roteiro atualizado com sucesso.''
redirect_to :action => ''show'', :id => @roteiro
else
render :action => ''edit''
end
end
But this way my RoteiroTipo objects are not validated the way they should
be, adding errors to the correct instances so that they are shown in the
edit page.
What''s the best way to solve this?
Thanks
Erick
_______________________________________________________
Promoo Yahoo! Acesso Grtis: a cada hora navegada voc acumula cupons e concorre a
mais de 500 prmios! Participe! http://yahoo.fbiz.com.br/