Avoiding Ruby hash conditionals in Ruby on Rails

This gets really old: if params[:teacher] && params[:teacher][:id] … so instead, do this: if params[:teacher].try(:[], :id) or do it a lot more: name = params[:company][:owner][:name] if params[:company] and params[:company][:owner] and params[:company][:owner][:name] turns into: name = params.try(:[], :company).try(:[], :owner).try(:[], :name) Yay for Stack Overflow!

jsTree: adding Expand All and Collapse All buttons

The documentation for jsTree is thorough, but not particularly easy to read. If you are looking for an easy way to add “Expand All” and “Collapse All” buttons, here’s one way: <input type=”button” value=”Collapse All” onclick=”$(‘#tree_container_id’).jstree(‘close_all’);”> <input type=”button” value=”Expand All” onclick=”$(‘#tree_container_id’).jstree(‘open_all’);”> where ‘#tree_container_id’ is, of course, the ID of the container node for your tree.

Uploadify: changing scriptData with dropdowns

Uploadify is a pretty awesome jQuery/flash uploader. It’s made even more awesome by the stuff you can do with it on the fly. For example, if you want to pass a variable chosen from a dropdown via the uploader, you can use uploadifySettings() to do so. Some people appear to have problems with this part, … [Read more…]

Music industry shifts to being a service? Good news, bad news…

Here’s an interesting read from Ars Technica: Did file-sharing cause recording industry collapse? Economists say no The most interesting paragraph I see in this article is this one: So what is emerging is an increasingly “ephemeral” global music culture based not upon the purchasing of discrete physical packages of music, but on the discovery and … [Read more…]

Testing CKEditor in Ruby on Rails with Cucumber/Capybara

I have a textarea with the id of “request_details”, made into a CKEditor instance by jQuery: $(‘#request_details’).ckeditor(); (Check this page if you need some help getting CKEditor to work with jQuery, it’s dead simple) Feature looks like this:  And I fill in “Here are some details” in the CKEditor instance “request_details” Step looks like this: … [Read more…]