Not appear error message


I have a partial form “empresa”. In new.rhtml of “empresa”, I call the
partial form of “usuario”. Well, it is happening the following: When
save empresa, and stop in validates, as much in “empresa” how much
“usuario”, appear only error message of “empresa”, and not of “usuario”.
Because this happening?

ps1.: I use flash_message instead of flash[:notice]
ps2.: The “validates” of “usuario” is functioning, does not only appear
msg. If save only usuario, in new.rhtml of “usuario”, the msg`s appearl,
only when call in partial form of “empresa”

_form Empresa

<%= error_messages_for ‘empresa’ %>
<%= error_messages_for ‘usuario’ %>
<%= flash_message %>


_form Usuario

<%= error_messages_for ‘usuario’ %>
<%= javascript_include_tag ‘forms’ %>
<%= stylesheet_link_tag ‘componentes’ %>
<%= flash_message %>

Razão social: <%= text_field :empresa, :razao_social, :size => 50, :maxlength => 50 %>
Nome fantasia: <%= text_field :empresa, :nome_fantasia, :size => 50, :maxlength => 50 %>


Nova Empresa

<%= form_remote_tag(:update => 'aux_div', :url => {:action => 'create'}, :success => visual_effect(:highlight, "fundo"), :complete => "centraliza('view')")%> <%= render :partial => 'form' %> <%= render :partial => '/usuarios/form'%>


<%= submit_tag "Salvar", :class => 'botao2' %><%= link_to 'Cancelar', {:controller => 'login', :action => 'index'}, :class => 'botao2'%> <%= end_form_tag %>

model Usuario

class Usuario < ActiveRecord::Base

belongs_to :empresa

attr_accessor :senha1, :senha2

validates_presence_of   :nome ,:message => "Preencha o campo Nome"
validates_presence_of   :senha1,:message => "Preencha o campo Senha"
validates_presence_of   :senha2,:message => "Preencha o campo

Confirmação de senha"
validates_presence_of :email, :message => “Preencha o campo
validates_uniqueness_of :email, :message => “Este e-mail já esta

model Empresa

class Empresa < ActiveRecord::Base

has_many :usuarios

validates_uniqueness_of :cnpj, :message => “Este CNPJ/CPF já esta
validates_presence_of :cnpj, :message => “O campo CNPJ/CPF precisa ser
validates_presence_of :razao_social, :message => “O campo Razão Social
precisa ser preenchido”

Nome: <%= text_field :usuario, :nome %>
E-Mail: <%= text_field :usuario, :email %>


Hi Marcelo,

this is quite a common question. And an annoyance for many people,
including me. Luckily it is very easy to solve, look at for a detailed solution. That
should do the trick.

Kind regards,

Nick S.
Compare Rails hosting companies