Move a chunk of non-markup ruby code from a view to the controller