Synthesis : Scott Becker

New version of AssetPackager

Thanks to Dan Kubb for alerting me to a new version of JSMin, the library used by AssetPackager to compress javascript.

With the release of the latest jQuery 1.1.1, it triggered a bug in how jsmin was treating characters within a regexp.

AssetPackager now has the latest version.

Also, for those using Prototype, the v1.5 release that comes with Rails 1.2.1 has a missing semi-colon on line 846. This of course breaks when compressed. To fix it, this line should have a semi-colon at the end. This:

if (params && /Konqueror|Safari|KHTML/.test(navigator.userAgent)) params += '&_='

Should be:

if (params && /Konqueror|Safari|KHTML/.test(navigator.userAgent)) params += '&_=';

Update: Michael Schuerig has posted this to the rails trac so hopefully this will be fixed soon. In the meantime, it’s pretty simple to make the change yourself.

Comments Off on New version of AssetPackager

Hash – to_query

Look what just appeared in Rails trunk – Hash#to_query – turn a hash of values into a form-encoded query string. I’ve wanted this on occasion in the past. Check it out:

Simple Conversion

{:a => 10}.to_query

Becomes this:

a=10

Nested Conversion

{:person => {:name => 'Nicholas', :login => 'seckar'}}.to_query

Becomes this:

person[name]=Nicholas&person[login]=seckar

Multiple Nested

{:person => {:id => 10}, :account => {:person => {:id => 20}}}.to_query

Becomes this:

account[person][id]=20&person[id]=10

Array Values

{:person => {:id => [10, 20]}}.to_query

Becomes this:

person[id][]=10&person[id][]=20

You can do the same thing in Prototype:

$H({ action: 'ship', order_id: 123, fees: ['f1', 'f2'], 'label': 'a demo' }).toQueryString();

Becomes this:

'action=ship&order_id=123&fees=f1&fees=f2&label=a%20demo'

It doesn’t look like Prototype handles the nested conversions yet though.

Comments Off on Hash – to_query