Thursday, June 7, 2012

Multiple Select Combo Form for Rails

I was trying to find the way to make a dropdown combo box with multiple selection for a Rails project. There are many tips in the documentation and online, but I could not find the right way to make sure the options were initialized to their proper values when the form is created. For example, if a book already belongs to categories "fiction" and "mystery," how to make sure that those are already selected and highlighted on the form. This is what I finally arrived at. A key point is that the column name needs to be “{collection}_ids” and not simply “{collection},” in order for the right choices to be automatically selected when the form is built. This example would be used in selecting multiple categories to apply to some model.
= fields_for :record do |form|
  = form.label :category_ids, “Categories”
  %br
  = form.select :category_ids, 
       Category.collect {|x| [x.name, x.id]}, {}, :multiple => true
I think the standard update action in the controller will handle this without any special action. To do the update manually, you could just say
@record.update_attributes(:category_ids=>params[:record][:category_ids])

See the Rails doc at http://bit.ly/LDDSma.

Wednesday, April 25, 2012

Add Check-in, Check-out to Dropbox

Dropbox is a great solution for online backup and, to some extent, for simple collaboration. One limitation, however, is that there is no way to know when a collaborator has opened a file for editing. If two people edit a file at the same time, Dropbox will save both edited files which will not have conflicting changes.

Notifybox is a third-party solution to this problem. It only works with Microsoft Office documents and on Windows, but it does seem workable and is free for use on a single folder.

When you open a file within a monitored folder, a dialog pops up:

image

If you choose “Check-out,” you can go ahead and edit the file. When you save and close it, Notifybox informs you that it is now checked-in.

If you choose “Cancel” instead, a dialog box tells you that you should close the file without saving it. This isn’t enforced, so it’s up to the user to pay attention to the prompts.

If you try to open a file that is already checked out by someone else, a different message tells you that you should close the file without saving since it is already in use. It appears that all the potential users must be using Notifybox … I don’t think that it can tell if someone has checked out a file unless that person is also using Notifybox.

It’s a simple solution that bridges a gap between Dropbox and more complex version control systems that are likely too intimidating for most casual users.

A full subscription costs $6 monthly and allows you to monitor multiple folders and subfolders, and to encrypt and compress files in your Dropbox folder. The free version lets you monitor a single folder.

Wednesday, March 28, 2012

Dead Paypal Security Key

imagesJust on the off chance someone else has the same problem … My PayPal security key is several years old and last night it finally quit. It flashed these messages when turned on:

88888888
(some gobbledygook strange characters)
batt  75
--E994--
Soft3328

I presume it means the battery was low, which wouldn’t be surprising. Well, should I just give it to my son to play with, or try to change the battery? I paid $5 for it but now they don’t even sell the key-chain model, and the credit-card model costs $30. Plus, I’m in Nigeria and it would take a good while to get a replacement.

I opened it up, which is fairly easy, and found a standard CR2032 lithium battery. I slid it out and slid in a new one. Uh oh, same error message! Well, let it sit for a while without the battery, I thought. So I took it out again, waited 5 minutes, then put the new one in. Now it just shows 88888888 no matter what! The button does nothing, the display does not turn off after a minute. Shorting some of the pads inside doesn’t do anything either. So now it’s no use even as a dumb toy.

It all makes sense, though. The key works by generating a 6 digit number every 30 seconds, and the number is verified by PayPal as belonging to your key. That means it’s tied to real clock time. If the battery is low and the unit thinks it may be unable to assure the accurate time, then it has to fail. Once that state has occurred, there should be no way to restore the correct state. Changing the battery doesn’t change the fact that the time has become suspect. Waiting 5 minutes before changing the battery probably put the key into a factory new state where it is waiting for programming.

Bottom line: If your security key fails, don’t bother trying to fix it. My own feeling is that it’s not worth $30 for the current credit-card-size key unless you have a weak password or are really careless with it, but then I might feel differently if I see a $3000 fraudulent charge on my account some day!