"Quick View of Pieces", now cookie-driven, boolean conversion
I finished off a feature tonight. If you saw the demo video of my designer service, I showed a feature that will allow you to view all the thumbnails of a project while viewing a single "piece". As of tonight, the app now remembers if you like your thumbnails to be shown or hidden.
I ran into some trouble implementing this until I realized that when you read and write to a cookie, you have to do so with a string. I was trying to set a boolean value, and like-wise when I was reading the value out I was treating it as a boolean. Ruby no-likely. (As opposed to Coldfusion which just automatically converts the value for you.)
In order to get around this problem I wrote a little converter function. It takes a string, and converts it to a boolean. (See code here.) (For all you Ruby guys out there...) If there is an easier way of doing this, or something in Ruby that already does this conversion, please let me know.
I ran into some trouble implementing this until I realized that when you read and write to a cookie, you have to do so with a string. I was trying to set a boolean value, and like-wise when I was reading the value out I was treating it as a boolean. Ruby no-likely. (As opposed to Coldfusion which just automatically converts the value for you.)
In order to get around this problem I wrote a little converter function. It takes a string, and converts it to a boolean. (See code here.) (For all you Ruby guys out there...) If there is an easier way of doing this, or something in Ruby that already does this conversion, please let me know.

1 Comments:
There's probably an even more concise way to do this in Ruby, but I would do:
def self.string_to_boolean(string_to_convert)
string_to_convert == 'true' ? 'true' : 'false'
end
This will return 'false' if a nil string is passed in, as your method does.
Post a Comment
<< Home