Note that there are some explanatory texts on larger screens.

plurals
  1. PODo not show error messages when validate a form
    primarykey
    data
    text
    <p>When the form is validated, this must show the error message. However it´s not showing.</p> <p>My view looks like this:</p> <pre><code>&lt;% form_for :invite, :url =&gt; profile_invites_path do |f| -%&gt; &lt;%= f.error_messages %&gt; &lt;p&gt;&lt;label for="email_to"&gt;&lt;%= t 'invites.new.labels.mail'%&gt;&lt;/label&gt;&lt;br/&gt; &lt;%= f.text_field :email_to %&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="role_id"&gt;&lt;%= t 'invites.new.labels.role'%&gt;&lt;/label&gt;&lt;br/&gt; &lt;%= collection_select(:invite, :type, Role.players , :name, :printable_name) %&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="message"&gt;&lt;%= t 'invites.new.labels.message'%&gt;&lt;/label&gt;&lt;br/&gt; &lt;%= f.text_area :message %&gt;&lt;/p&gt; &lt;p&gt;&lt;%= submit_tag "#{ t 'application.send'}" %&gt;&lt;/p&gt; &lt;% end -%&gt; </code></pre> <p>My model looks like this </p> <pre><code>class Invite &lt; ActiveRecord::Base self.inheritance_column = "invite_type" RE_EMAIL_NAME = '[\w\.%\+\-]+' # what you actually see in practice #RE_EMAIL_NAME = '0-9A-Z!#\$%\&amp;\'\*\+_/=\?^\-`\{|\}~\.' # technically allowed by RFC-2822 RE_DOMAIN_HEAD = '(?:[A-Z0-9\-]+\.)+' RE_DOMAIN_TLD = '(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)' RE_EMAIL_OK = /\A#{RE_EMAIL_NAME}@#{RE_DOMAIN_HEAD}#{RE_DOMAIN_TLD}\z/i MSG_EMAIL_BAD = "should look like an email address." # Validates validate :validate_presence_mail, :message =&gt; :"email.blank" validates_format_of :email_to, :on =&gt; :update, :with =&gt; RE_EMAIL_OK, :message =&gt; MSG_EMAIL_BAD validates_uniqueness_of :email_to, :on =&gt; :update, :scope =&gt; :profile_id, :message =&gt; :"email_to.taken" validates_presence_of :token validates_uniqueness_of :token validates_length_of :message, :minimum =&gt; 5 def validate_presence_mail presence_of(self.email_to, "email.to") end def presence_of(attrib, field) if attrib.blank? error_path = I18n.t "activerecord.errors.full_messages.#{field}.blank" self.errors.add_to_base("#{error_path}") end end end </code></pre> <p>Although error messages syntax is specified in the view and errors are added in the model, they are not being shown. </p> <hr> <p>This is the form in the view</p> <pre><code>&lt;% content_for :header do -%&gt; &lt;% t 'invites.new.title'%&gt; &lt;%= configatron.site_name %&gt; &lt;% end -%&gt; &lt;% content_for :sidebar do -%&gt; &lt;p&gt; &lt;% t 'invites.new.indication'%&gt; &lt;/p&gt; &lt;% end -%&gt; &lt;% form_for @invite, :url =&gt; profile_invites_path do |f| -%&gt; &lt;%= f.error_messages %&gt; &lt;p&gt;&lt;label for="email_to"&gt;&lt;%= t 'invites.new.labels.mail'%&gt;&lt;/label&gt;&lt;br/&gt; &lt;%= f.text_field :email_to %&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="role_id"&gt;&lt;%= t 'invites.new.labels.role'%&gt;&lt;/label&gt;&lt;br/&gt; &lt;%= collection_select(:invite, :type, Role.players , :name, :printable_name) %&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="message"&gt;&lt;%= t 'invites.new.labels.message'%&gt;&lt;/label&gt;&lt;br/&gt; &lt;%= f.text_area :message %&gt;&lt;/p&gt; &lt;p&gt;&lt;%= submit_tag "#{ t 'application.send'}" %&gt;&lt;/p&gt; &lt;% end -%&gt; &lt;%= link_to "#{ t 'application.back'}", profile_invites_path %&gt; </code></pre> <p>This is the new controller</p> <pre><code>def new @invite = Invite.new end def index @profile = current_user.profile @ps_invites = Invite.of_profile(@profile.id).for_powerful_supplier.available.count @ubc_invites = Invite.of_profile(@profile.id).for_business_contact.available.count respond_to do |format| format.html # index.html.erb format.xml { render :xml =&gt; @invites } end end def create @invite = Invite.of_type(params[:invite][:type]).of_profile(current_user.profile.id).available.first unless @invite.nil? @invite.status = 'pending' @invite.message = params[:invite][:message] @invite.email_to = params[:invite][:email_to] if @invite.save InviteMailer.deliver_send_invite(@invite) flash.now[:notice] = t 'invites.messages.sent' redirect_to(profile_invites_url) else flash.now[:error] = t "invites.messages.not_sent" render :controller =&gt; 'invites' ,:action =&gt; "new" end else flash.now[:error] = t("invites.messages.without_invite", :profile_type =&gt; params[:invite][:type]) render :controller =&gt; 'invites' ,:action =&gt; "new" end end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload