RAILS auto_complete With Additional FILTER

Auto complete with additional filter

The best tutorial about auto complete control by far was one from Ryan Bates. It worked like a charm, and he made it look so easy. Only problem I had with it was that I wanted another control on the form to filter the auto-complete control.
The tutorial didn’t cover that, so I got stranded in a strange place. The solution was pretty simple, but it took me a while to figure it out. If you are just beginning Rails like I am – this is rigth tutorial for you.

(more…)

Ruby BLOCKS Explained 101

Blocks

Block is basically anonymous method that gets called from another method. If you have some code that executes passed in method like this:

def execute_method_in_block(named_method)
    named_method.call
    named_method.call
end

execute_method_in_block Proc.new {puts "Hello, blocks are cool!"}

You can write it like this using blocks:

def execute_method_in_block
    yield
    yield
end

execute_method_in_block  {puts "Hello, blocks are cool!"}

We’ve lost “Proc.new” and a method name, we are just saying

Whenever you find yield, execute block that is defined within braces.

You might be wondering what’s the fuss all about, (more…)