2013-07-05 72 views
-2

不顯示simple_form錯誤通知我使用Zurb基金會和簡單的形式使用zurb基礎

<%= simple_form_for @complaint do |f| %> 
    <%= f.error_notification %> 

    <%= f.association :company, as: :radio, label: false %> 
    <%= f.input :country, priority: ["United States"] %> 
    <%= f.input :city %> 
    <%= f.input :client, placeholder: 'Coca-Cola' %> 
    <%= f.input :body %> 

    <%= f.button :submit %> 
<% end %> 

在我的模型:

class Complaint < ActiveRecord::Base 
    belongs_to :company 
    attr_accessible :body, :city, :client, :country, :company_id 
    validates :company, presence: { message: 'Company cannot be blank!' } 
    validates :body, presence: true 
    validates :country, presence: true 
    validates :city, presence: true 
end 

當我點擊提交一個空的形式,我希望有錯誤的說'公司不能空白!'等等

我是不是用<%= f.error_notification %>不正確? 我怎樣才能到那裏顯示錯誤?

回答

0

不要把它當作逐字,因爲我只有幾個月進入rails自己,但我不認爲error_notification是用來顯示錯誤的: - 錯誤本身打算顯示在組件旁邊。不過,我有一個情況使用f.input_field的f.error場中的元件旁邊是凌亂的,所以我想我在頁面頂部的所有錯誤,所以我創建了一個簡單的部分:

-if object.errors.any? 
    .alert{:class => "alert-error"} 
    %p= "Please correct the following #{pluralize(object.errors.count, 'error')}:" 
    %ul 
     - object.errors.full_messages.each do |msg| 
     %li= msg 

,並呈現在它頁面頂部:

= render "layouts/errors", :object => @booking 

對不起,哈姆。

.alert{:class => "alert-error"} 

樣式它與通知相同。

0

請問您可以顯示您的控制器CREATE操作代碼。我有類似的錯誤,問題在那裏。

您可能已經使用@ complaint.save!而不僅僅是@ complaint.save

你應該調用保存而不是保存!所以if語句可能會失敗,對象將在其錯誤對象中包含消息,並且simple_form可以在render:new之後將它們呈現在每個表單輸入旁邊。

+0

對不起,我不再工作在該回購,並沒有控制器代碼。 – emailnitram