加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Heroku上的Rails check_box表现不正常

发布时间:2020-12-17 02:00:33 所属栏目:百科 来源:网络整理
导读:我在Rails 3.1模型中有一些布尔属性,而我刚刚通过迁移添加的两个新属性在Heroku(Cedar)上无法正常工作.他们在本地正常工作,我也在使用PostgreSQL(版本9). 移民: class AddNotificationSettingsToCollections ActiveRecord::Migration def change add_column
我在Rails 3.1模型中有一些布尔属性,而我刚刚通过迁移添加的两个新属性在Heroku(Cedar)上无法正常工作.他们在本地正常工作,我也在使用PostgreSQL(版本9).

移民:

class AddNotificationSettingsToCollections < ActiveRecord::Migration
  def change
    add_column :collections,:email_comments,:boolean,:default => true
    add_column :collections,:email_selections,: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

问题是,复选框始终显示为未选中,但是当我检查控制台时,模型ALWAYS将属性设置为true.当我拖尾Heroku日志文件时,我可以看到为这些字段设置了正确的参数(1).

我错过了什么吗?我在这种形式的其他布尔字段工作正常.这可能与默认值有关吗?

解决方法

我也有这个问题.我最终得到了一个愚蠢的解决方法.我知道这不是一个好的解决方案,但这是我的:

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

这很难看,但它在Heroku上以相同的设置完成了这项工作.希望有更优雅的解决方案……

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读