Blah Blah Woof Woof

Archived content 2005-2007

observe_field and radio buttons

Posted by Tim Riley Tue, 14 Mar 2006 05:20:00 GMT

Without specifying any extra options for Ruby on Rails’ radio_button or radio_button_tag form tag helpers, each tag will share the same id and name attributes.

While the name attribute needs to be shared for a set of radio buttons to work properly, sharing the id attribute is not necessary and will also break the observe_field JavaScript helper. In this case, the field observer will only be triggered for any events in the first of the radio buttons with the specified id.

Fortunately, you can set the id manually:


 <%= radio_button_tag "button_name",
   "button_val",
   checked,
   :id => "my_custom_id" %>

Then, using a separate observer for each radio button in your set with a unique id, you can effectively observe any change in the set. Watch out, radio buttons!

Posted in Geek | no comments | no trackbacks

She’s got me whistling her private tune

Posted by Tim Riley Thu, 16 Feb 2006 03:51:00 GMT

I love it when there is whistling in songs, because it is fun and easy to whistle along and sound good. It is much harder to sing along to a song and sound so good.

Posted in Music | 2 comments | no trackbacks

First lists of 2006

Posted by Tim Riley Mon, 06 Feb 2006 11:12:00 GMT

Artists who recently sang in French, though I thought they never would:
  • Per Gessle
  • Shakira
Eponymous albums recently purchased from CD Baby: 1980s situational comedies I wish I had watched with greater lucidity:
  • Growing Pains
  • Family Ties
  • The Hogan Family
  • Perfect Strangers

Posted in General, Music | 4 comments | no trackbacks

The plural of cul-de-sac is culs-de-sac

Posted by Tim Riley Mon, 30 Jan 2006 14:16:00 GMT

Tonight I started building a Ruby on Rails technology demo in order to sharpen some of my skills with the framework. Already I have learnt something – while Rails’ conventions are cool and help you write less code, sometimes you need to supplement them. For example, if you want to add an extra singular/plural pair, used for the names of models, controllers (singular) and tables (plural), add something like the following in config/environment.rb (some examples are in there already commented):


 Inflector.inflections do |inflect|
  inflect.irregular 'nudie', 'nudies'
 end

It is the Inflector that handles the magic of pluralisation in Rails. There is some useful info on its wiki page. You can test this pluralisation online.

Also, be sure to quickly peruse the wiki page about magic field names before creating fields in your database tables.

Posted in Geek | no comments | no trackbacks

Conditional periodically_call_remote in Rails

Posted by Tim Riley Tue, 24 Jan 2006 02:53:00 GMT

Loading new sections or pages in a Rails app using AJAX can do a lot to increase overall application snappiness and lengthen the life cycle of each page load, but if any of these pages use the periodically_call_remote helper, then these periodical calls may persist longer than you would like.

The trick to fix this is to note that in the documentation for periodically_call_remote, the options for defining the target URL and callbacks are the same for the link_to_remote helper, which include an option called :condition.

So if you want your periodical calls to cease when different pages in your app are loaded using AJAX, then use the :condition option to have periodically_call_remote check against a variable:


 <%= periodically_call_remote(
   :condition => "check_var == true",
   :update => "my_update_div",
   :frequency => 20,
   :url => { :action => "bar" }) %>

Then in your templates define check_var true or false depending on whether you want the periodical updates to take place:


 <script type="text/javascript">
   //<![CDATA[
     check_var = true;
   //]]>
 </script>

The :condition option can take any sort of JavaScript code, you can be as creative as you like in defining when and under exactly what conditions your periodical calls are made. Take back control!

Posted in Geek | no comments | no trackbacks

Multiple AJAX submit buttons in a Rails form

Posted by Tim Riley Mon, 16 Jan 2006 10:29:00 GMT

In a Ruby on Rails app, if you have multiple submit buttons in a web form, the value of the button pressed is not serialised with the rest of the form and so it won’t be available to the controller in the @params hash. This is a ticket for this in the Rails bug tracking system, where a workaround for the problem is documented:


 <%= hidden_field 'update_button', 'Edit' %>
 <%= submit_tag 'Edit', :name => '_update_button' %>
 <%= submit_tag 'Cancel', :name => '_update_button', 
   :onclick => "Form.getInputs(this.form, null, 'update_button')[0].value = 'Cancel'" %>

A hidden form element (which actually gets serialised) is used to pass the value of the submit buttons to the controller, and the JavaScript code in the onclick event for the second of the buttons above updates the value of the hidden field depending on which button is pressed.

I thought this was a pretty nifty workaround, but in my case, I was submitting a form using AJAX, and my buttons were created using submit_to_remote instead of submit_tag. The problem here was that submit_to_remote does not let you specify an :onclick option, since the method uses the onclick event internally in order to submit the form using JavaScript (see the code for the method in the documentation).

So, in order to have an AJAX-submitted form with multiple submit buttons that actually passes the value of the button clicked to the controller, it was necessary to quickly re-implement submit_to_remote in the view:


 <% hidden_field_tag 'per_page', '20' %>
 <% [ '20', '40', '60' ].each do |num| %>

   <% remote_options = {
     :update => "dock",
     :loading => "showLoading();",
     :complete => "hideLoading();",
     :with => "Form.serialize(this.form)",
     :url => { :action => "query" } } %>
   <%= tag("input", {
     :type => "button",
     :onclick => "Form.getInputs(this.form, null, 'per_page')[0].value = '#{num}'; #{remote_function(remote_options)}; return false;",
     :name => "show_num",
     :value => "Show #{num}" },
  false) %>

 <% end %>

This way, you can specify the script to update your hidden variable before including the script that was part of submit_to_remote that is used to submit the form.

Using the example above, you now you can refer to @params[:per_page] in order to get the value of the button that was clicked to submit the form.

The whole reason I had to head down this path was in order to work around a silly rendering bug in Internet Explorer that was causing problems for the NetFox administration interface. In the end, we decided that this particular workaround was suboptimal and chose a different solution altogether. Is it any coincidence that my left eye has started to twitch uncontrollably since I started having to fix bugs caused by IE?

Posted in Geek | 1 comment | no trackbacks

Bad Hair Day!

Posted by Tim Riley Thu, 12 Jan 2006 13:40:00 GMT

Per says: “I’ve got boxes and drawers of so many songs & ideas & rubbish lying around my house and I just felt like sharing all this with you guys out there! I guess it’s basically for the hardcore fan, but still, it’s kinda interesting if you’re into the mesmerizing enigma of songwriting…”

Today Per Gessle released a collection of demos for his smash-hit Swedish Mazarin album, freely available to download, along with PDF cover art!

I love these rare moments when smart musicians actually get the internet. This is a great way for Per to reward his fans and to stimulate further interest in his music, without detracting at all from the prominence of his for-sale works. Encouragingly, it looks like there will be much more unreleased music to come, under the “Bad Hair Day” moniker.

Posted in Music | no comments

Mike's a journalist

Posted by Tim Riley Tue, 10 Jan 2006 03:12:00 GMT

My friend Miklos recently had an article of his about wedding photography posted on dailyshooter.com. Interesting read!

Posted in General | no comments

Adelaide Breaks Collective Summer Jam!

Posted by Tim Riley Mon, 09 Jan 2006 09:12:00 GMT

So the Spring Jam was pretty happening, but I have a feeling this will be even bigger. Get down to Sugar on Rudle St this Friday night for a tasty dose of Adelaide breaks.

I’ll be going to Schutzenfest for a bit before this, so Friday the 13th should bring some pretty fun times, all things considered :)

Posted in Life, Music | no comments

Music to hack to

Posted by Tim Riley Sat, 07 Jan 2006 23:20:00 GMT

Matt Palmer asks what music people like to listen to when coding. My preference is to listen so a good seamless mix of electronic music, usually driving and upbeat.

The Cloud Factory Collective’s web site is a great place to get music to hack by. Some choice mixes:

My friend Adam Bellinson has recently started DJing drum & bass mixes on Linux using the open source tool Mixxx. I have been enjoying his work a lot too. The mixes can be downloaded from his torrents page.

One track I acquired recently with an iTMS voucher I got for Christmas is the Back to the Future overture from the soundtrack of the first film. Although it is only 8 minutes in length, I have found this to be very enjoyable to have playing especially when overcoming big bugs or problems in code, because the emotion that is conveyed in the piece makes me feel like I am a hero like Marty McFly saving the fabric of space and time :-)

Posted in Geek, Music | no comments

Older posts: 1 ... 4 5 6 7 8 ... 10