www.flickr.com
Michael Kovacs' photos More of Michael Kovacs' photos
Recommend Me Cable Car Software logo

Saturday, August 26, 2006

Rails realities part 18 (Multi-part parameter parsing)

Rails has the ability to automagically parse the date parameters that are created from using the various date_helper methods that create select inputs. But the problem is that in order to have that magic parsing happen you have to do a mass assignment of parameters to the object that contains the value.

Well sometimes you'd like to just grab the value of the date without having to do a mass parameter assignment on your object.

Here's an example of how the form parameters are passed in when using a built in rails date helper:
{"date(1i)"=>"2006", "date(2i)"=>"8", "date(3i)"}

Today's post provides some code extracted right out of ActiveRecord that will do this without having to do the mass assignment.

Anyway, here's a link to the code:
http://www.bigbold.com/snippets/posts/show/2476

I did this in about 10 minutes so I make no claims about the robustness here. I tested it on one date select group and it worked fine. Corrections and improvements are definitely welcomed but this seems like a good candidate to be extracted into a helper within rails.

Comments:

Post a Comment





<< Home

This page is powered by Blogger. Isn't yours?