Entries in Computing (187)

Sunday
Feb102013

Misleading minus signs in Cucumber progress format

I have been recently using the Ruby test tool Cucumber and came across a little annoyance.  In the progress format output there were unexpected minus signs:

  $ cucumber --format progress features/codebreaker_submits_guess.feature
  ---..........................................
  14 scenarios (14 passed) 42 steps (42 passed)
  0m0.117s 
  $

Normally minus signs would be used to indicate skipped steps but here they seem to be displayed for each scenario outline step whether it is skipped or not.

A little Googling revealed that this is a known bug that has not yet been fixed because of the awkward internal design of Cucumber.

Sunday
Dec302012

How to Inhibit Escaping in Rails3 ActionView Custom Helpers

I had bits of code like this scattered throughout my Rails3 views:

  <%= image_tag(thumbnail_image_path(@image.id)) %>

I wanted to enclose each image_tag call in a <div></div> pair to allow styling, so I wrote the following custom helper and placed it in app/helpers/application_helpers.rb:

  def thumbnail_block(image_id)
    "<div>#{image_tag(thumbnail_image_path(image_id))}</div>"
  end

I then replaced the calls to image_tag in my views with calls to thumbnail_block:

  <%= thumbnail_block(@image.id) %>

However, instead of displaying the images, this displayed the HTML code in the browser window.  Rails3 was automatically escaping the string produced by the new custom helper.

A search on Google lead me to this answer by Mike Fisher at StackOverflow and this post by Yehuda Katz at Rails Dispatch.  These gave me the solution: the custom helper needs to mark the string as html_safe before returning it:

  def thumbnail_block(image_id)
    "<div>#{image_tag(thumbnail_image_path(image_id))}</div>".html_safe
  end

Now my images display properly.

Monday
Nov192012

How to set Query Parameters in Rails form_for URLs

In Rails 3.2.8, the following code fragment:

  <%= form_for @resource, url: {p: '123'} do |f| %>

generates this HTML:

  <form accept-charset="UTF-8" action="/resource/new?p=123" ... >

Multiple query parameters also work:

  <%= form_for @resource, url: {p: '123', q: 'ABC'} do |f| %>

gives:

  <form accept-charset="UTF-8" action="/resource/new?p=123&q=ABC" ... >
Thursday
Aug162012

Firefox Right-Click Menus in Ubuntu Unity

Following my upgrade from Ubuntu 10.04 LTS to 12.04 LTS, my greatest annoyance with the Unity interface has been the way it broke my web browsing experience.  When using Firefox I make much use of Control-Right-Click to open multiple bookmark menu items.  In Unity, this simply just does not work.  The cause of this appears to be changes made to Firefox to integrate it with the Unity global menu.  Fortunately, these changes can be removed quite easily.  In the Firefox menus click:

Tools > Add-ons > Global Menu Bar integration > Disable > Restart now

Now the Firefox menus will respond correctly to Control-Right-Clicks. 

Disabling Global Menu Bar integration also means that the Firefox menus stay at the top of the Firefox window instead of going up to the global menu bar.  This will please my wife who found Firefox under Unity very confusing: "Where have all the menus gone?  Where's my back button?  Where's the address box?  What have you done to my Firefox?  It no longer works.  I want the old one back".  I suspect that these reactions will be fairly typical of the majority of Ubuntu users.

Sunday
Aug122012

The Ubuntu Unity Super Key on a Thinkpad

Since 2005 I have had a IBM Thinkpad R50e laptop on which I have run various releases of Ubuntu from 5.04 onward.  Recently I upgraded from Ubuntu 10.04 LTS to 12.04 LTS.  The change in interface from Gnome 2 to Unity was a profound shock to my system and it took me several weeks to get used to it.  At one point I even installed Debian 6 in an attempt to get back to a system I felt more at home with (however, I quickly went back to Ubuntu when I realized Debian does not come with Firefox readily available). 

The main problem facing anyone using Unity on a Thinkpad is the lack of a 'Windows' key.  Unity maps its 'Super' key onto the Windows key, and the Super key is at the heart of how the Unity interface operates, being the basis for many keyboard shortcuts.  Without it you will spend a lot of time switching back and forth between mouse and keyboard.

The solution I chose was to map Caps Lock to the Super key as follows: 

System Settings > Keyboard Layout > Options > Caps Lock key behaviour > Make Caps Lock an additional Super

Now pressing Caps Lock brings up the Unity Dash.