Archive for the ‘Programming’ Category

Mass animations with jQuery

In a recent web app project that uses jQuery on the client we needed to animate many many HTML elements (about 1500) at once and synchronously. As the normal animate method of jQuery does the animation on each element setting its element style one gets pretty fast into performance troubles when doing such mass animations. [...]

A voting extension from scratch for Rails 3 (Part 2 – Testing environment)

In the last episode we created the basic structure for the make_voteable gem. With “test first” in mind we now set up our RSpec testing environment for developing the make_voteable gem. We already installed RSpec at the beginning of this blog series. First we need to create a testing folder (named spec) directly under the [...]

A voting extension from scratch for Rails 3 (Part 1 – Overview and setup)

This blog series is about creating a voting extension for Ruby On Rails. There are already some others voting extensions available, but none is currently up-to-date 1 or ActiveRecord compatible 2. So let’s build one from scratch. It is also (or maybe even more) a blueprint of current best practices on how to build those [...]

Check your params

I just asked myself (and the community) where validating and cleaning up the GET/POST parameters would fit best in Rails. lebreeze at Stackoverflow suggested a sanitize_params method that is called by a before_filter in the ApplicationController. I agree that the ApplicationController is a good place, but I don’t like the fact that it is called [...]

Index external models with Sunspot/Solr

Lately I wanted to index all tags of ActsAsTaggableOn for full text search and autosuggestions using Solr resp. Sunspot. The ActiveRecord models of ActsAsTaggableOn are unfortunately not directly accessible as they are located in the ActsAsTaggableOn gem. Fortunately that is pretty easy to solve by using metaprogramming techniques. So I added an additional initializer named [...]

Intend to extend (metaprogramming in Ruby)

In this post I want to illustrate the different ways of how to extend Ruby classes and instances. As being a former Java developer it is always impressive, but also sometimes a bit confusing how many ways are available in Ruby to achieve that. There is already a lot written about this topic (see resources [...]

QuerySolr – a jQuery Solr library

Today I released QuerySolr. It is a small jQuery library for easily sending Ajax Solr requests. A Solr query using QuerySolr looks like this: $.querysolr({ host: "127.0.0.1", port: "8983", params: { q: "*:*", fq: "type:car" }, callback: function(data) { // do something with the returned Solr JSON results } }).query(); // and finally send the [...]

Autocompletion / autosuggestion using Solr

There are several options available for getting autocompletion/autosuggestion to work with Solr. Below is an overview of these options and their advantages respectively disadvantages. If you have a question about one of these techniques then please feel free to leave a comment (just added DISQUS as comment system to my blog). I will write another [...]

Ticker – a jQuery UI Twitter like ticker

When you are not logged into Twitter and visit the start page an elegant live ticker shows up. I also wanted something like this, so I created one on top of the jQuery UI framework. In the most simple way (just rotating) you can create it on a div containing a list <div id="ticker"> <ul> [...]

Update attributes and OpenStruct

Rails does have the conveniet method update_attributes to update one or more attributes of an ActiveRecord instance. Sometimes this is also very handy for standard Ruby objects and pretty easy to implement: class MyClass attr_accessor :foo, :bar   def update_attributes(hash) hash.each_pair do |key, value| begin self.send("#{key}=", value) rescue # do something when an attribute does [...]