我有@selected_posts
- selected_post
对象的数组。 每个selected_post
有名称和信息。通过一组对象过滤对象rails
而且我还有一个ActiveRecord的模型
PublishedPost < ActiveRecord::Base
end
,我需要选择发布的所有职位,其中
published_post.name == selected_post.name and published_post.info== selected_post.info
我该怎么办呢?
我想是这样的:
PublishedPost.where("name in ? AND info in ?", @selected_posts.map(&:name) @selected_posts.map(&:info))
你是否应该首先将'PublishedPost'作为一个独立的课程?只需在posts表上使用[enum column](http://api.rubyonrails.org/v5.1/classes/ActiveRecord/Enum.html)即可完成您的工作。 'enum status:[:draft,:published,:trashed]' – max
是的,我应该把'PublishedPost'作为单独的表格,因为数据库结构已经被定义并且不是由我写的 – user2950593