我的网站上有一个搜索表单,以此形式提交网址(这些是标记ID)
http://localhost:3000/tags?utf8=✓&q=2%2C12%2C44
它适用于第一个标签ID,但不适用于其他标签ID
def self.search(query = {})
output = self.scoped
output = output.where(:id => query[:q])
end
TagsController:
def index
@tags = Tag.search(params)
end
答案 0 :(得分:0)
ActiveRecord::Base.where
接受数组作为参数。要将查询参数转换为数组,可以使用split
:
output = output.where(:id => query[:q].split(','))