0
如何查询搜索数组与where
?什么是正确的方法?正确的方法来搜索一个数组而不是在哪里
û有这样的关联:
# Foo has many bars
Foo.first.bars
控制器:
def index
@bars = []
@datas = Foo.where(email: current_user.email)
@datas.map { |d| @bars.push(d.bar).where("name like ?", "%#{params[:email]}%") }
respond_to do |format|
format.html
format.json { render json: @bars }
end
end
而不是where
为阵,什么是正确的查询词?
你是指从Enumerable中查找?,你可以给它一个块并搜索数组中的元素。 [ref to doc](https://ruby-doc.org/core-2.3.3/Enumerable.html#method-i-find) – Axe