Ruby on Rails problems & solutions - Jan 18, 2011

January 18, 2011

Subscript Ahoy!

This one is simple enough, and I’d done it before, long, long ago.  But I had to look it up that day.  Gotta show chemicals in your HTML page?  Subscript, ahoy!

Dynamic Table striping

This article:

Describes in great detail, how to achieve zebra striping on your tables using jQuery, and even adds a hover-color, which is cool and all, but…

Relevant code:

What about when I dynamically load a new part of my page, in response to some user action.  And the new part has a table in it.  The $(document).ready only runs once.  My new table doesn’t have the stripey goodness.  Or, if I just reload a table by itself via Ajax?  Or just the tbody rows (hello, paging)?  How about if I just freaking add a new row (insert_before)?

So, hover color changing.  That one is deceptively simple.  Instead of .mouseover, you should be doing a .live(‘mouseover’,…  That’s what ‘ live’ is for, after all.

Now, how about striping?  Well, WTF was this example doing, anyway?  Proving you can play with CSS in Javascript, I guess.  Forget the Javascript part, and just use a CSS selector (.stripeMe tr:even instead of ‘alt’)  Done.

Of course, having figured all this out, we started using the jQuery Datatable component, and now it’s all irrelevant.  Oh, well.  I learned something.

And, last, but not least

GUID/UUID generation

Ever needed to generate UUID/GUID’s?

Nice little gem

Too bad it doesn’t work with the current version of REE (1.8.7) (ffi incompatible with Ruby version < 1.9 now)

This one works with REE:

Read the whole thread for all the variations people use to do this. Sort of scary, actually.

} else { $('#cookie-notice').show(); } $('#cookie-notice-accept').click(function() { createCookie('cookie-notice-dismissed','true',365); // Change from 1 month to 1 year. $('#cookie-notice').hide(); });