Snippets

Thu Jun 21

The ActiveRecord documentation for date_select contains the cryptic statement:
 
"The selects are prepared for multi-parameter assignment to an Active Record
object."
10 minutes googling later...
"Besides that, it's now possible to do multi-parameter assigns that can  
even be type-casted. This is extremely helpful to do something like
this for date attributes:

post.attributes = {
"written_on(1i)" => "2004",
"written_on(2i)" => "6",
"written_on(3i)" => "16"
}

If the written_on attribute is of the date type, this is turned into:

post.written_on = Date.new(2004, 6, 16)

The number in the parentheses òepresents the position in the
constructor and the i represents the type cast from string to integer
(you can also cast to floats or arrays)."