Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Rails 3.2积垢:。其中带有';或';有条件的_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby Rails 3.2积垢:。其中带有';或';有条件的

Ruby Rails 3.2积垢:。其中带有';或';有条件的,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,有了ruby on rails,我想做如下工作: @tasks = Task.where(:def => true || :house_id => current_user.house_id) 最有效/干净的方法是什么?您可以这样做: Task.where("def = ? or house_id = ?", true, current_user.house_id) 一般情况是: Model.where("column = ? or other_column = ?", val

有了ruby on rails,我想做如下工作:

 @tasks = Task.where(:def => true || :house_id => current_user.house_id)

最有效/干净的方法是什么?

您可以这样做:

Task.where("def = ? or house_id = ?", true, current_user.house_id)
一般情况是:

Model.where("column = ? or other_column = ?", value, other_value)
您还可以利用Arel:

t = Task.arel_table

@tasks = Task.where(
  t[:def].eq(true).
  or(t[:house_id].eq(current_user.house_id))
)