ruby-on-rails – Heroku在Rails中读取字符串而不是整数?
发布时间:2020-12-17 02:04:32 所属栏目:百科 来源:网络整理
导读:在使用Postgres版本9.1.9的Heroku Cedar堆栈上运行的Rails 3.2.2应用程序中. 执行以下方法时: class Post ActiveRecord::Base def shared_to_all privacy 1 == 1 endend 我遇到这个错误: Completed 500 Internal Server Error in 19msNoMethodError (undef
在使用Postgres版本9.1.9的Heroku Cedar堆栈上运行的Rails 3.2.2应用程序中.
执行以下方法时: class Post < ActiveRecord::Base def shared_to_all privacy & 1 == 1 end end 我遇到这个错误: Completed 500 Internal Server Error in 19ms NoMethodError (undefined method `&' for "0":String): app/models/post.rb:75:in `shared_to_all' app/controllers/application_controller.rb:212:in `next_post' “privacy”在heroku数据库的DDL中定义为“int4 DEFAULT 0”. irb(main):008:0> Post.first.shared_to_all => false irb(main):009:0> Post.first.privacy.class => Fixnum irb(main):010:0> Post.first.privacy & 1 == 1 => false 解决方法
事实证明,它可能只是数据库迁移中的一个小故障,因为我已经尝试回滚并再次迁移,现在它似乎工作正常.不知道是否应该删除或留下问题以防其他人遇到同样的问题.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |