用户和地点是具有has_many realtionship的两个节点
@places = User.find(4).places
@places = @places.where(dog: false) if params[:no_dogs]
我可以将这两者合二为一,这样如果param出现那么它就会涉及其他条件下忽视它的条件
答案 0 :(得分:0)
我不相信find()
方法接受零参数。也许你想要这个?
@places = User.places # Calling the association gives an unexecuted proxy to a query to build
@places = @places.where(dog: false) if params[:no_dogs]
或者,如果您想使用User
模型:
@users = User.all
@users = @users.where(dog: false) if params[:no_dogs]