0

undefined method where使用这些参数运行以下代码时,我不断收到错误消息。

谁能看到我做错了什么?

谢谢

 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?
4

2 回答 2

1

User.allArrayuser objects使用它时返回你一个这样where的错误 NoMethodError: undefined method `where' for Array

所以改用以下

@pieces = Piece.where(:category_id => params[:category_ids])
于 2012-09-21T06:19:16.417 回答
0

它应该是:

Piece.where(:category_id => params[:category_ids]) if params[:category_ids].present?

于 2012-09-21T06:09:49.770 回答