Forum: Ruby on Rails Not appear error message

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ccf0f43fe1adcaf0992e9576f0eb4494?d=identicon&s=25 Marcelo Junior (mr_brownstone)
on 2007-01-20 17:53
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 %>

    <td><label for="empresa_razao_social">Razão social:</label></td>
    <td><%= text_field :empresa, :razao_social, :size => 50, :maxlength
=> 50  %></td>
    <td><label for="empresa_nome_fantasia">Nome fantasia:</label></td>
    <td><%= text_field :empresa, :nome_fantasia, :size => 50, :maxlength
=> 50  %></td>

_form Usuario
<%= error_messages_for 'usuario' %>
<%= javascript_include_tag 'forms' %>
<%= stylesheet_link_tag 'componentes' %>
<%= flash_message %>
    <td><%= text_field :usuario, :nome %></td>
    <td><%= text_field :usuario, :email %></td>

<h2>Nova Empresa</h2>
<%= 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"
91308e9bc88cb069fd1bcf88e910d042?d=identicon&s=25 Nick Snels (nicksnels)
on 2007-01-21 10:01
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 Snels
Compare Rails hosting companies
This topic is locked and can not be replied to.