Forum: Ruby on Rails Not appear error message

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Marcelo J. (Guest)
on 2007-01-20 18: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 %>
<!--[form:empresa]-->

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


_form Usuario
-------------------------------
<%= error_messages_for 'usuario' %>
<%= javascript_include_tag 'forms' %>
<%= stylesheet_link_tag 'componentes' %>
<%= flash_message %>
<!--[form:usuario]-->
<table>
  <tr>
    <td><label>Nome:</label></td>
    <td><%= text_field :usuario, :nome %></td>
  </tr>
  <tr>
    <td><label>E-Mail:</label></td>
    <td><%= text_field :usuario, :email %></td>
  </tr>
(....)



new.rhtml
------------------------------
<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'%>
<p>
<label>-----------------------------------------------------------</label>
</p>
<%= 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
E-Mail"
    validates_uniqueness_of :email, :message => "Este e-mail já esta
cadastrado"
(....)



model Empresa
--------------------------------------
class Empresa < ActiveRecord::Base

  has_many :usuarios

  validates_uniqueness_of :cnpj, :message => "Este CNPJ/CPF já esta
cadastrado"
  validates_presence_of :cnpj, :message => "O campo CNPJ/CPF precisa ser
preenchido"
  validates_presence_of :razao_social, :message => "O campo Razão Social
precisa ser preenchido"
end
Nick S. (Guest)
on 2007-01-21 11: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
http://railsforum.com/viewtopic.php?id=717 for a detailed solution. That
should do the trick.

Kind regards,

Nick S.
--
http://www.railshostinginfo.com
Compare Rails hosting companies
This topic is locked and can not be replied to.