2011-11-09 21 views
4

我有我只是通過遷移添加在Rails 3.1模型的一些布爾屬性和兩個新的沒有在Heroku(雪松)正常工作。他們在當地正常工作,在那裏我也使用PostgreSQL(版本9)。Rails的check_box行爲不正確

遷移:

class AddNotificationSettingsToCollections < ActiveRecord::Migration 
    def change 
    add_column :collections, :email_comments, :boolean , :default => true 
    add_column :collections, :email_selections, :boolean , :default => true 
    end 
end 

視圖(HAML)

%li 
    %label{:for => 'collection_email_comments'} 
    = f.check_box :email_comments 
    Email me when comments are made 
%li 
    %label{:for => 'collection_email_selections'} 
    = f.check_box :email_selections 
    Email me when a selection is made 

問題是,該框總是顯示爲未選中,但該模型總是有當我檢查控制檯設置爲真正的屬性。當我尾部Heroku的日誌文件,我可以看到正確的參數被設定爲這些字段(1)。

我錯過了什麼嗎?我有其他布爾字段在這種形式工作正常。這可能與默認值有關嗎?

+0

當你有一個新的集合實例(即剛創建,還沒有在數據庫中)或從數據庫加載的集合時,複選框未被選中? –

+0

從db加載 – Callmeed

+0

幾個小時後,我剛剛修好了自己。 :/ – Leopd

回答

1

我在這個問題上也是如此。我結束了一個愚蠢的解決方法。我知道這不是一個很好的解決方案,但是這是我的:

= f.check_box :email_comments, {:checked => (@collection.new_record? ? true : @collection.active)} 

這是醜陋的,但在相同的設置做的工作,我在Heroku上。希望在那裏有一個更優雅的解決方案...