Reputation: 4992
I've got some boolean attributes in a Rails 3.1 model and two new ones I just added via a migration aren't working properly on Heroku (Cedar). They are working properly locally, where I'm also using PostgreSQL (ver 9).
Migration:
class AddNotificationSettingsToCollections < ActiveRecord::Migration
def change
add_column :collections, :email_comments, :boolean , :default => true
add_column :collections, :email_selections, :boolean , :default => true
end
end
View (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
Problem is, the checkbox is ALWAYS displaying as unchecked, but the model ALWAYS has the attributes set as true when I check the console. When I tail the Heroku log file, I can see that the correct parameter is being set for these fields (1).
Am I missing something? I have other boolean fields in this form that work fine. Could this be related to the default value?
Upvotes: 4
Views: 399
Reputation: 2386
I was having this issue as well. I ended up with a stupid workaround. I know it's not a good solution, but this is mine:
= f.check_box :email_comments, {:checked => (@collection.new_record? ? true : @collection.active)}
It's ugly, but it did the job for me on Heroku in an identical setup. Hopefully there is a more elegant solution out there...
Upvotes: 1