0

如何显示 status.name 等于数组中项目的所有票证?

带有 select 的单个项目似乎像这样工作

@project_tickets = @project.tickets.select { |m| m.status.name == "new"] }

但不是一系列项目

params[:array_here] = ["new","implemented"]

@project = Project.find_by_id(params[:project_id])
@project_tickets = @project.tickets.select { |m| m.status.name == [params[:array_here]] }
4

4 回答 4

2

你要求的方式是这样的:

@project_tickets = @project.tickets.select { |m| params[:array_here].include? m.status.name }

但是你真的应该把它委托给数据库。

@project_tickets = Ticket.includes(:status).where(:project_id => @project.id, :status => { :name => params[:array_here] })
于 2012-12-13T06:28:37.567 回答
0

where工作?

@project_tickets = @project.tickets.where("name = ?", params[:array_here])
于 2012-12-13T06:20:02.920 回答
0
 @new_tickets=@project.tickets.select { |m| m.status.name == params[:array_here][0] }

 @implemented_tickets=@project.tickets.select { |m| m.status.name == params[:array_here][1] }
于 2012-12-13T06:21:08.853 回答
0
params[:array_here] = ["new","implemented"]

@project = Project.find_by_id(params[:project_id])
@project_tickets = @project.tickets.select { |m| params[:array_here].include?(m.status.name) }
于 2012-12-13T06:24:59.663 回答