RailsCasts Pro episodes are now free!

Learn more or hide this

Erik Chan's Profile

GitHub User: echan00

Site: http://www.erikchan.com

Comments by Erik Chan

Avatar

DO THIS INSTEAD!!

$(document).on("click", "#products .pagination a", function() {
$.getScript(this.href);
return false;
});

Avatar

We can even easily change the JavaScript to make the search ‘live’ so that the results automatically update with each keypress. Note that this is only a quick demo and isn’t the best way to do this. There are several jQuery plugins that you can use if you do something like this in a production app. To do this we’ll replace the JavaScript that we used to submit the form through AJAX with this.

Can someone explain why this isn't the best way to do this? And what jQuery plugins to look at?

I've added the jquery.observe_field.js plugin to add a delay but my search/sort is laggy on my production server.

Avatar

This will make it case insensitive

ruby
  def self.search(search)
    if search
      #case insensitive
      where(['LOWER(name) LIKE LOWER(?) ', "%#{search}%"])
    else
      where(nil)
    end
  end