当用这些参数运行下面的代码时,我总是收到一个错误undefined method where
。Rails in In不知道在哪里
任何人都可以看到我做错了什么?
感谢
Parameters: {"category_ids"=>["1", "3", "4"]}
@pieces = Piece.all
@pieces = @pieces.where(:category_id => params[:category_ids]) if params[:category_ids].present?
@pieces = @pieces.where(:brand_id => params[:brand_ids]) if params[:brand_ids].present?
@pieces = @pieces.where(:color_id => params[:color_ids]) if params[:color_ids].present?
@pieces = @pieces.where(:user_id => params[:friend_ids]) if params[:friend_ids].present?
即使它是通过过滤所有这些过滤器?也许我应该使用:条件? - 谢谢顺便说一下:) – Dol
或者你的意思仅仅是第一@ piece.where应该是Piece.where? – Dol
Piece.all不返回给你一个ActiveRelation。这意味着,你不能在其上运行“where”。相反,所有Piece.all都会返回一个Piece对象数组。 –