Ruby on rails 布尔验证

Ruby on rails 布尔验证,ruby-on-rails,ruby,ruby-on-rails-4,sqlite,Ruby On Rails,Ruby,Ruby On Rails 4,Sqlite,我在这里面临一个小问题。 我使用以下代码从数据中获取数据 class CreateGrounddetails < ActiveRecord::Migration def change create_table :grounddetails do |t| t.string :name t.datetime :working_hours t.string :address t.string :contact_no t.string :email t.i

我在这里面临一个小问题。 我使用以下代码从数据中获取数据

class CreateGrounddetails < ActiveRecord::Migration
 def change
  create_table :grounddetails do |t|
   t.string :name
   t.datetime :working_hours
   t.string :address
   t.string :contact_no
   t.string :email
   t.integer :number_of_grounds
   t.text :description
   t.boolean :featured_ground #Featured  
   t.timestamps null: false
  end
 end
end
class CreateGrounddetails
我有一个布尔值存储在字段“featured_ground”中,现在我只想获取“featured_ground”的值为“TRUE”的数据。 我怎样才能做到这一点

先谢谢你

你可以这么做

Grounddetail.where(featured_ground: true)

这将为您提供所需的记录。

假设您的模型将命名为
Grounddetail
,则以下操作将完成

Grounddetail.where(:featured_ground => true)
您可以使用

Grounddetail.where(:featured_ground => true).to_sql


非常感谢。。。我对如何做到这一点感到非常沮丧..谢谢:)嘿,非常感谢你的回答..现在我想要一个在特定时间段内是真实的特写背景..我该怎么做?这并不能回答这个问题。若要评论或要求作者澄清,请在其帖子下方留下评论-您可以随时对自己的帖子发表评论,一旦您有足够的评论,您就可以发表评论。-如果这不是一个答案,那么它是什么?你的答案被标记为“太短”,实际上不超过一个评论。我建议您添加更多细节,让用户了解“为什么”,它可能是一个好的,也可能是最好的。让用户了解原因有助于他们在其他类似的情况下。我想特写在特定时间段内是真实的背景。我该怎么做?
Grounddetail.where(featured_ground: true)
Grounddetail.where(:featured_ground => true)