Archive for the Category Ruby

 
 

DWTF Open Source License




Scott Raymond’s “Ajax on Rails” contains a nifty trick for form fields, following the Rails mantra of DRY and convention over configuration. Creating a field with an associated label, error checking, and formatting is as simple as

  1.  
  2.    <%= f.text_field :phone %>
  3.  

This produces a label using the humanized “Phone: “, a <div> for holding validation errors, an input tag, and appropriate field values. Here’s a complete form using Scott’s hackery from page 298:

  1.  
  2. <%# See +standard_form+ in application_helper.rb %>
  3.   <%= f.text_field :name %>
  4.   <%= f.date_select :start_date, :label => "First Call" %>
  5.   <%= f.date_select :end_date, :label => "Last Call" %>
  6.   <%= f.text_field :phone %>
  7.   <%= f.text_field :email %>
  8.   <%= f.text_area :body, :label => "Notes" %>
  9.   <%= standard_submit %>
  10. <% end %>
  11.  

Scott’s magic is embodied in a form helper, LabelingFormBuilder. For yucks, I Googled in search of a Rails plugin by that name. I stumbled across labeling_form_builder from Seth Rasmussen. I peeked at the license. Seth cracked me up. Only in open source can you get away with this (words bleeped):

  1.  
  2.            DO WHAT THE F**K YOU WANT TO PUBLIC LICENSE
  3.                    Version 2, December 2004
  4.  
  5. Copyright (C) 2007-2008 Seth Thomas Rasmussen
  6.  
  7. Everyone is permitted to copy and distribute verbatim or modified
  8. copies of this license document, and changing it is allowed as long
  9. as the name is changed.
  10.  
  11.            DO WHAT THE F**K YOU WANT TO PUBLIC LICENSE
  12.   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  13.  
  14.  0. You just DO WHAT THE F**K YOU WANT TO.
  15.