2015-04-05 67 views
1

我正在使用Wrapbootstrap下載的模板,設計用於用戶註冊和登錄,但沒有得到任何錯誤彈出。設計錯誤消息沒有顯示引導程序模板

在所有我對設計的看法中,我打電話給<%= devise_error_messages! %>

在我的模型如下驗證:

validates :first_name, presence: true 
    validates :last_name, presence: true 
    validates :phone_number, presence: true 

這裏是我的Devise_helper.rb

module DeviseHelper 
    def devise_error_messages! 
    return '' if resource.errors.empty? 

    messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join 
    html = <<-HTML 
    <div class="alert alert-error alert-block"> <button type="button" 
    class="close" data-dismiss="alert">x</button> 
    #{messages} 
    </div> 
    HTML 

    html.html_safe 
    end 
end 

這裏是我註冊的新視圖頁:

  <!--=== Content Part ===--> 
     <div class="container content"> 
     <div class="row"> 
     <div class="col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2"> 
     <form class="reg-page"> 
     <div class="reg-header"> 
     <h2>Register a new account</h2> 
     <p>Already Signed Up? Click <%= link_to "Sign In", login_url %> to login your account.</p> 
     </div> 
     <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> 
     <%= devise_error_messages! %> 

     <label>First Name<span class="color-red">*</span></label> 
     <%= f.text_field :first_name, autofocus: true, :class=> "form-control margin-bottom-20" %> 

     <label>Last Name<span class="color-red">*</span></label> 
     <%= f.text_field :last_name, autofocus: true, :class=> "form-control margin-bottom-20" %> 

     <label>Phone Number<span class="color-red">*</span></label> 
     <%= f.text_field :phone_number, autofocus: true, :class=> "form-control margin-bottom-20" %> 

     <label>Email Address <span class="color-red">*</span></label> 
     <%= f.email_field :email, autofocus: true, :class=> "form-control margin-bottom-20" %> 

     <div class="row"> 
     <div class="col-sm-6"> 
     <label>Password <span class="color-red">*</span></label> 
     <% if @validatable %> 
     <em>(<%= @minimum_password_length %> characters minimum)</em> 
     <% end %> 
     <%= f.password_field :password, autocomplete: "off", :class=> "form-control margin-bottom-20" %> 
     </div> 

     <div class="col-sm-6"> 
     <label>Confirm Password <span class="color-red">*</span></label> 
     <%= f.password_field :password_confirmation, autocomplete: "off",:class=> "form-control margin-bottom-20" %> 
     </div> 
     </div> 

     <hr> 

     <div class="row"> 
     <div class="col-lg-6 text-right"> 
     <%= f.submit "Sign up", :class=> "btn-u" %> 
     </div> 
     </div> 
     </form> 
     </div> 
     </div> 
     <% end %> 
     </div><!--/container--> 
     <!--=== End Content Part ===--> 

當我提交了一個未完成的表單,如下所示:http://localhost:3000/login?utf8=%E2%9C%93&authenticity_token=v%2BKndd3om3fBChpsZ6riw%2FVBiVM1ehVbKgBF9tIlg6PB6p30oei7OU3toqthjU1TY67yI3gmzjigxGe5DWfX7w%3D%3D&user%5Bemail%5D=&user%5Bpassword%5D=fwf&user%5Bremember_me%5D=0&commit=Log+in

回答

1

這種嘗試在你的幫助文件:

message_html << "<div class="alert alert-error alert-block"> <button type="button" class="close" data-dismiss="alert">x</button>" 
message_html.html_safe 

而且,在你的頁面佈局或相應的登錄頁查看Flash消息:

<% if flash[:alert] %> 
    <span class='flash_error'> <%= flash[:alert] %></span> 
    <% end %> 
+0

我應該在哪裏放它,我總是收到一個錯誤,試圖添加它 – Zippo9 2015-04-05 05:03:34

+0

嘗試在devise_helper.rb中替換相應的代碼文件 – sansarp 2015-04-05 05:04:33

+0

沒有變化。仍然沒有錯誤消息正在顯示。是否有我的代碼的其他部分我應該發佈 – Zippo9 2015-04-05 05:11:16

0

有原因的,這是因爲模板我正在使用自己的Javascript錯誤消息,這是重寫設計的錯誤消息。這兩個錯誤消息都沒有顯示出來,直到我刪除了包含在Wrapbootstrap模板中的JS,並且它現在可以工作