0

actually i have a problem as i want to search all the result when i select All from category.As now i have 4 options in my category. I have a query to find the result against three categories like tha,

This shows the result against 3 categories like againt home,apartment and plaza,But when i select all then nothing happen.What i should do that when i select all then all the properties will show.Thanks

  • What is `params["search"]`? – Stefan Oct 15 '14 at 08:31
  • there are three param which are 'home','apartment' and 'plaza'.Now i add a 4th option in select category which is 'all'.When i selct all and press search button nothing happen but a error appear "incompatible character encodings: UTF-8 and ASCII-8BIT" – user3602222 Oct 15 '14 at 08:53
  • If you are passing user supplied data straight to your database, your application becomes vulnerable to [SQL injection](http://guides.rubyonrails.org/security.html#sql-injection). – Stefan Oct 15 '14 at 09:01
  • oh.Then any suggesstion please – user3602222 Oct 15 '14 at 09:03

1 Answers1

1

Try something like that :

@properties = Property.includes(:rooms)
@properties = (params["search"] == 'ALL') ? @properties.all : @properties.where(params["search"])
@properties = @properties.paginate(:page => params[:page], :per_page => 8)

In my code, I suppose the value for 'All category' would be 'ALL'

Fred
  • 1,607
  • 20
  • 33