Rails check_box on Heroku not behaving correctly

I have some boolean attributes in the Rails 3.1 model, and two new ones that I just added through migration do not work properly on Heroku (Cedar). They work correctly locally, where I also use PostgreSQL (version 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 

The problem is that this flag is ALWAYS displayed as unchecked, but with the ALWAYS validation model, attributes set to true are validated. When I close the Heroku log file, I see that the correct parameter is set for these fields (1).

Am I missing something? I have other Boolean fields in this form that work fine. Could this be due to the default?

+4
source share
1 answer

I also had this problem. I ended up with a stupid workaround. I know this is not a very 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. Hope there is a more elegant solution ...

+1
source

Source: https://habr.com/ru/post/1380452/


All Articles