rails 4条件来自表的值

时间:2014-09-28 09:43:23

标签: ruby-on-rails ruby-on-rails-4

我创建了一个名为category的属性表。该类别具有不同的价值“机场”,“景点”等。

如何找到“景点”类别中的所有位置?

我试过这个:

@sights_markers = Location.where(:category = 'sights') 

和这个

@sights_markers = Location.where('category = sights') 

和这个

@sights_markers = Location.where('category = sights') 

但这给了我一个错误。

请告知..谢谢......很高兴

2 个答案:

答案 0 :(得分:1)

简单,

    @sights_markers = Location.where(category: 'sights') 

请至少阅读一次。 http://guides.rubyonrails.org/active_record_querying.html

答案 1 :(得分:0)

你犯了一个错误,这样做,它会起作用:

@sights_markers = Location.where(:category => 'sights') 

@sights_markers = Location.where("category = 'sights'")