2016-01-19 148 views
-5

我在这里面临一个小问题。 我取使用下面的代码数据的数据,布尔验证

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 

我有一个存储在域“featured_ground”一个布尔值,现在我想只获取其是否有“featured_ground“真”值数据”。 我该如何做到这一点?

预先感谢您。

+0

检查生成的SQL我想有地面我period..how能做到这一点是一定时间真? –

回答

1

你可以做

Grounddetail.where(featured_ground: true) 

它给你预期的记录。

+1

非常感谢...我很沮丧,因为如何做到这一点..感谢:) –

+0

嘿谢谢这个答案很多..现在我想特点地面是真的在一定的时间.. ..我可以做到这一点吗? –

0

下面应该这样做,假设您的模型将被命名为Grounddetail

Grounddetail.where(:featured_ground => true) 

您可以通过使用

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

OR

Grounddetail.where(:featured_ground => true) 
+0

这不提供问题的答案。要批评或要求作者澄清,在他们的帖子下留下评论 - 你总是可以评论你自己的帖子,一旦你有足够的[声誉](http://stackoverflow.com/help/whats-reputation),你会能够[评论任何帖子](http://stackoverflow.com/help/privileges/comment)。 - [来自评论](/ review/low-quality-posts/10943334) –

+0

如果这不是一个答案,那么它是什么? –

+1

你的答案被标记为“太短”,实际上不仅仅是评论。我建议你添加更多的细节,让用户理解“为什么”它可能是一个好的或者最好的。让用户了解原因可以帮助他们处理其他类似情况。 –