Hash extension - no more hash.try(:[], key)
Rails: timeline_fu and workflow integration
Quick tip on how to integrate timeline_fu and workflow callbacks.
Run irb from file
In case I forgot.
Rails 3 remote update form
Rails 3 brings some nice unobstrusive javascript. This very short tutorial will show how to make simple yet powerful ajax update form.
First, grab jquery-ujs file (or gem). Next, create some model and REST controller.
Controller needs a small change:
Thats pretty self explaining: when object is valid send notice message, else send errors as json array.
View:
Only the :remote => true part is important.
Some JavaScript
This code will take remote form and register callbacks for showing loader, notice message and errors list.
And thats all, it simply works. And yes, you have to write CSS on your own ;]
Better (scoped) rails engines routing
Rails engines are really great, but they are missing one thing - putting in router scope. Fortunately, this can be easily fixed.
Instead of engine`s config/routes.rb file put all router stuff in lib/engine.rb like that:
And now it is possible to add scope:
Done!
Example gist2,5 times faster heckle
RSpec has built-in support for heckle, but executing every “$ spec spec_file —heckle my_method” from command line is boring.
Why not use rake?
Yeah, nice one! Well, not really. “$ rake heckle_all” takes about 87 seconds to complete. First line executes shell script “spec” that runs ruby, then spec with heckle, then next line starts its own ruby again and again. Ruby starts slowly. Can it be done better?.
Yes! After some hacking I ended up with something like this:
Woohoo, “$ rake heckle_all” now takes “only” 33 seconds. Thats 2,5 times faster! ;]
Yes, I know, nothing to be excited about, but imagine you have some more code. One hour instead of two and a half! Isn`t that impressive?
It couldn`t be a benchmark post without nice chart