Bug for the day

If you’ve got a date_select in a partial on a collection and the date in the AR object isn’t being rendered by the date helper (and it defaults to Time.now) then the fix is to pass an :object parameter to the date_select holding the AR object (which is the partial’s local in my case). Got that?

eg

<%= render :partial => 'duck', :collection => @list_of_ducks %>

<%= date_select("duck"+duck.ref, "dob", :object => duck) %>

This one had me trawling the rails source on my hands and knees!

observe_form values lost in the ether

When using observe_form, there’s a sneaky nastyness. (Rails 1.2.3) It’s a bit inconsistent. Hopefully this will clear it up.

With no ‘update’ or ‘with’ parameter then the values aren’t passed:
new Form.Observer('theform', 1, function(element, value) {new Ajax.Request('/controller/action', {asynchronous:true, evalScripts:true})})

Surely this is a bug? It should include ‘parameters:value’.

Using - :with => ‘values’
new Form.Observer('theform', 1, function(element, value) {new Ajax.Request('/controller/action', {asynchronous:true, evalScripts:true, parameters:'values=' + value})})

Getting there but still doesn’t quite work. Try it and you’ll see why.

Using - :update => {}, and no ‘with’
new Form.Observer('theform', 1, function(element, value) {new Ajax.Updater({}, '/controller/action', {asynchronous:true, evalScripts:true, parameters:value})})

This now works as it’s changed to use the Ajax.Updater passing the parameters as we wanted in the first attempt.
I hope his saves someone some time :-)

Credits due here for the empty hash fix: http://wiki.rubyonrails.org/rails/pages/observe_form+-+Passing+Parameters

Events missed by the almighty Prototype!

This one’s worth knowing: http://dev.rubyonrails.org/ticket/7895

The problem I encountered was that EventObserver (Prototype) or observe_field (RJS equivalent) only fire the first time on radio buttons. It would be nice to see if Prototype 1.6.0 will fix this, but alas, I’ve not got time for such luxuries right now. Anyone else tried?