2010-12-28 13 views
0

フォームが検証されると、これはエラーメッセージを表示する必要があります。しかし、それは表示されません。フォームの検証時にエラーメッセージを表示しない

私の見解は次のようになります。

<% form_for :invite, :url => profile_invites_path do |f| -%> 
<%= f.error_messages %> 
<p><label for="email_to"><%= t 'invites.new.labels.mail'%></label><br/> 
<%= f.text_field :email_to %></p> 

<p><label for="role_id"><%= t 'invites.new.labels.role'%></label><br/> 
<%= collection_select(:invite, :type, Role.players , :name, :printable_name) %></p> 

<p><label for="message"><%= t 'invites.new.labels.message'%></label><br/> 
<%= f.text_area :message %></p> 

<p><%= submit_tag "#{ t 'application.send'}" %></p> 
<% end -%> 

エラーメッセージの構文はビューに指定されているとエラーがモデルに追加された、彼らはされていませんが、私のモデルは、この

class Invite < ActiveRecord::Base 
    self.inheritance_column = "invite_type" 

    RE_EMAIL_NAME = '[\w\.%\+\-]+'       # what you actually see in practice 
    #RE_EMAIL_NAME = '0-9A-Z!#\$%\&\'\*\+_/=\?^\-`\{|\}~\.' # 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 => :"email.blank" 
    validates_format_of :email_to, :on => :update, :with => RE_EMAIL_OK, :message => MSG_EMAIL_BAD 
    validates_uniqueness_of :email_to, :on => :update, :scope => :profile_id, :message => :"email_to.taken" 
    validates_presence_of :token 
    validates_uniqueness_of :token 
    validates_length_of :message, :minimum => 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 

のように見えます表示されます。


これは、ビュー

<% content_for :header do -%> 
<% t 'invites.new.title'%> <%= configatron.site_name %> 
<% end -%> 

<% content_for :sidebar do -%> 

<p> 
    <% t 'invites.new.indication'%> 
</p> 
<% end -%> 



<% form_for @invite, :url => profile_invites_path do |f| -%> 
<%= f.error_messages %> 
<p><label for="email_to"><%= t 'invites.new.labels.mail'%></label><br/> 
<%= f.text_field :email_to %></p> 

<p><label for="role_id"><%= t 'invites.new.labels.role'%></label><br/> 
<%= collection_select(:invite, :type, Role.players , :name, :printable_name) %></p> 

<p><label for="message"><%= t 'invites.new.labels.message'%></label><br/> 
<%= f.text_area :message %></p> 

<p><%= submit_tag "#{ t 'application.send'}" %></p> 
<% end -%> 

<%= link_to "#{ t 'application.back'}", profile_invites_path %> 

にこれは新しいコントローラ

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 => @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 => 'invites' ,:action => "new" 
     end 
    else 
     flash.now[:error] = t("invites.messages.without_invite", :profile_type => params[:invite][:type]) 
     render :controller => 'invites' ,:action => "new" 
    end 
    end 
end 

答えて

1

はこれで動作するはずである形式です:

<% form_for @invite, :url => profile_invites_path do |f| -%> 
+0

をいいえ、私は他の形態を持っています記号でこれらは誤りを取ります。 – maxiperez

+0

すみません、他のコメントは悪いです。エラーは私のものでした。あなたの解決策は正しいです – maxiperez

+0

すみません。今私は他の問題がある。検証は表示されますが、フォームを再度送信しようとすると、次のエラーが表示されます。未知の動作 アクションが応答しません2.アクション:access_denied、answer_message、check_roles、connections、destroy_picture、disconnect、edit、network、new、received_messages、role_requirements、 role_requirements =、s、save_picture、sent_messages、show、submit_pending_requests、switch_network_view、update、vote_negatively、vote_positively – maxiperez

関連する問題