假设我有一个Dog,我想在Rails中存储它是否为trained.Ruby方法通常有?个布尔值.Should I call the database column 103, or should I call the database column 101 and have a method

class Dog
  def trained?
    trained
  end
end

后一个选项似乎效率低下,尤其是当我有很多布尔字段时.

还是我还缺少其他的 Select ?

推荐答案

你应该叫它trained.在模式中使用:boolean类型定义它.你可以把它称为trained?,一切都会神奇地工作.

http://www.ruby-forum.com/topic/60847也是这么说的

Ruby-on-rails相关问答推荐

rails中Net::STP的多文件模式

Rails引擎importmap Uncaught ReferenceError:未定义tinymce

从Rails中的字符串中间提取子字符串

使用嵌套属性时如何自动将父 ID 分配为外键?

在 Rails 7 中,可以将导入映射与 js Bundle 解决方案一起使用,还是它们是专有的?

如何在 Ruby on Rails 中正确存储 BigDecimal

Rails 'includes' 和 'where' 与 belongs_to 和 has_many 关联

rake assets:precompile try 连接到数据库

注册表单上是否需要 CSRF 保护?

如何添加到序列化数组

RSpec 设置会话对象

Rails ActiveRecord 查询日期范围

您将如何在 RoR 中创建类似 SO 或 Facebook 的通知系统?

为什么 Ruby on Rails 使用 http://0.0.0.0:3000 而不是 http://localhost:3000?

在 Rails 路由中更改 id 参数

如何一次显示一条 Ruby on Rails 表单验证错误消息?

即使X-Frame-Options为ALLOWALL,也无法在 iframe 中显示我的 rails 4 应用程序

rake 任务中的 def 块

Sidekiq Rails 4.2 使用 Active Job 还是 Worker?有什么不同

ActionMailer 在开发 Rails 4 中不发送邮件