我目前正在尝试在ruby上编写一个过滤系统。
我有一张包含此信息的表格:
Tool.create(name: 'Confluence', image: 'confluence.png')
Tool.create(name: 'Git', image: 'git.png')
Tool.create(name: 'JIRA Core', image: 'jira-core.png')
Tool.create(name: 'JIRA Software', image: 'jira-software.png')
然后我与has_and_belongs_to_many
表
User
的关系
我希望能够搜索与多种工具相关联的人。
所以在我的代码中使用:
if params["Confluence"]
contractors = contractors.includes(:tools).where(tools: { name: "Confluence"})
end
我可以搜索数据库并返回数据进行一次搜索,但如果我尝试使用其他类似的东西:
if params["JIRA Core"]
contractors = contractors.includes(:tools).where( tools: {name: "JIRA Core"})
end
即使我的数据库中有反映这一点的数据,我也不会得到任何结果。
如果有人知道我哪里出错了,我将非常感激。