1

User and Place are the two nodes having has_many realtionship

@places = User.find(4).places

@places = @places.where(dog: false) if params[:no_dogs]

can I make these two into one so that if param comes then it involve where condition other wise ignore it

Vishal G
  • 1,521
  • 11
  • 30

1 Answers1

0

I don't believe that the find() method takes zero arguments. Maybe you're wanting this?

@places = User.places # Calling the association gives an unexecuted proxy to a query to build

@places = @places.where(dog: false) if params[:no_dogs]

Or if you wanted to work with the User model:

@users = User.all

@users = @users.where(dog: false) if params[:no_dogs]
Brian Underwood
  • 10,746
  • 1
  • 22
  • 34
  • then I can assume I need to use conditional where in queue like the way I mentioned and also mentioned – Vishal G Jan 04 '17 at 12:11