We are redoing our basement and wanted to put one of these really cool sofa’s with a recliner at each end and really fluffy – for the kids to site on while playing video games and even to sleep over – bu reclining the couch back and throwing on a blanket. Teenagers are tough. So we bought a nice Lane reclining sofa from Sams Club for $600 and brought it home.
But this thing was big and bulky and it did not look like it would go down the stairs or through a window. But we bought it anyways and let it sit in the garage for a week measuring things to see if it could go down the stairs or through a window. There seemed to be no solution until my brother Scott came over one evening and I told him this sad story of how we were going to take back the couch because it would not fit down the stairs.
Scott went into the living room where we had a similar couch and flipped it over – and pointed out that the three sections were simply bolted together and held together with two metal bars running across the bottom of the sofa. Eight easy-to-reach bolts and it would be in three pieces.
So we went back to the new couch and tore off the packaging – that probably meant that I could not take it back to Sam’s and get my money back. We flipped over the new Lane sofa and indeed it had the same construction as the Berkline sofa in the living room.
We removed the eight bolts and the three separatre couch pieces went easily down the basement stairs (it was much lighter). In 10 minutes I had it reassembled and up in the basement.
It just goes to show you that sometimes there is a simple solution hiding amongst all the complex solutions.
I already got my Christmas present
http://joehewitt.com/files/iphone/navigation.html.
This will cause me to lose a *LOT* of sleep! I will find it hard to focus on everyday tasks because of this. Good thing I have a few days off for Thanksgiving.
Tools to Pull a Whole Web Site Down Into your Hard Drive
Just random notes.
Rails Periodic Updater – Beware when you are putting them in Divs replaced by Ajax
This URL says it all:
http://tr.openmonkey.com/articles/2006/01/23/conditional-periodically_call_remote-in-rails
Quoting, “…but if any of these pages use the periodically_call_remote helper, then these periodical calls may persist longer than you would like.”
Little Things I love about Rails – This Time ActiveRecord
When you are setting a foreign key in an object you can do it using the id directly or through the helper method. In this example comments belong_to users.
# Using an object reference
u = User.get(1234)
c = Comment.new
c.user = u
# Old school
x = Comment.new
x.user_id = 1234
Yeah – that is what I like to see – a framework that respects programmer intelligence and gives us choices!
Making TinyMCE work in Ajax With Prototype and Ruby on Rails
Well – it was not nearly as easy as one would expect to make this work – but lots of folks have muddled their way through and I followed in their footsteps and fell into a few holes.
Smart folks should just use this code / plugin – which is pretty and clean
http://inplacericheditor.box.re/demos
I have not used it – but the demos are gorgeous.
So in this post, I do it the hard way. I won’t go into detail – it is all in the code below. Someday this might make a nice plugin – but it still has a flaw that I compensate for. Here is the basic outline: (1) include TinyMCE in the portal once – also init TinyMCE in portal.rhtml like this:
<%= javascript_include_tag "tiny_mce/tiny_mce.js" %>
tinyMCE.init({
mode : "none",
theme : "simple"
});
(2) In the div that will hold the editor – at the end of the output put in some Javascript to activate TinyMCE on the textarea in question, (2A) While you are there resize the columns so the text area is nice and wide, (2B) – before activating TinyMCE – figure out if TinyMCE has been pithed by too much Ajaxing – if a getInstanceById throws an error (even if not found it should return a null) – throwing an error indicates that MCE can’t even tell if something is *not* there. We declare MCE hosed, don’t even try to make it work – because it actually works half way, (2C) if it turns out getInstanceById works (returning null is OK) – we assume MCE is alive and activate MCE on the text area in question.
The next trick is catching the Save and Cancel (1) First we do a save from TinyMCE back to the div with a catch block so that when we are not even using TinyMCE because is unconscious – we will not confuse Prototype throwing errors, then (2) once the Ajax request is complete (onSuccess) we deactivate the TinyMCE attached to out textarea (again in a try/catch to eat errors if MCE has been knocked silly). Putting this in onSuccess is perfect because by then the server is updated and we are milliseconds away from wiping out the div – so we de-associate the MCE from the text area *just* before it vanishes in a puff of smoke.
So what puts MCE into a sleep-like state? When you are on an exit screen and you overwrite the div containing the editor from an external navigation operation. In Toozday – this is like going into Wiki, Editing a page, and then without pressing Save or Cancel you switch to Profile (oops – MCE left in limbo), then when you come back to Wiki and Edit – MCE is in a state unresponsiveness – waiting forever for its lost textarea to come back to it – which will never happen :(
I detect this in the Javascript and simply don’t use a zoned-out MCE – let users type in a text area I say! I warn the user to press Save or Cancel before continuing – hey if I charge their credit card twice – it is their fault!! Sooner or later users will learn to press Save or Cancel.
This condition is naturally reset when the whole page is refreshed – in Tooz this is on a Refresh, All Sites, or Site to Site Navigation. So MCE will start working again – leaving the user to wonder about the IQ of the system they are dealing with! MCE seems to come and go almost on a whim :)
Someday I will figure this out – but it is now on to more other fun stuff. Golly – everything I do ends up with some sticky wicket. Ah that is the fun of it all!
Below is the sweet code – with a lot of cool helpful urls that saved my arse and led me to the solutions. The URL to source is http://toozday.rubyforge.org/svn/trunk/app/
My First Monkey Patch for a Rails routes.rb bug
For the past five days I have been struggling with a bug in the route code in rails 1.2.3. I finally monkey patched url_for to essentially force it to do the obvious.
In this blog post, I describe the bug and how I reproduced it and then the patch to work around the bug.
There is a 10% chance that the routes is actually working and I just do not understand it. I read in the Agile book something about routes trying to use the shortest URL where possible – but the problem is that I have these long URLs to pass bits of session-like information around between my ajax calls – particularly when I want to go cross domain with my Ajax (i.e. I want to use a Rails tool from one server included into a web page from another server where cookies and session information will not be usable).
The bug comes down to when I call something with a long url with lots of stuff defined and then I generate a new url adding an id which is always at the end of the routes, url_for decides to “forget” the stuff that was to the left of it in the incoming request URL. Changing action only generates the *right* url while changing the action and id generates the wrong URL.
My Urls have three basic forms
/imsti.fe828-12345-bfea.1.right-content/comments/ajaxstart
/ajax.1.right-content/comments/ajaxstart
/comments/ajaxstart
The first two are for use in divs and never shown to the user. The imsti one both establishes a session and sets up the context and div name when the tool is being used cross-domain. The second is used when you are not going cross-domain and cookies are available to establish session because the ajax and the enclosing container are coming from the same server – so incoming ajax requests get the cookies.
Working on Samovar
Just some meaningless notes.
SI539 – Project Ideas
Just cleaning off my desktop – now that projects are all started…
Two Days – Two Rails Bugs
Rails is pretty awesome – but it is clearly a moving target in terms of how it works. Things work and then they break in different versions.
Today I am playing with routes and all I want it to do is check the routes in the priority order from first to last – but it seems to get confused when I add routes that don’t match at all in the routes.rb.
Yesterday’s bug was the breakage of the cookie_only feature by people who were intent on “fixing” a security bug – their fix broke a feature.
I get the sense that the bright folks in Rails have been working on 2.x for a while and that the second string in doing the maintenance on the 1.x.
I have a bad feeling that I will be checking out a copy of the rails source and fixing the damn bugs myself. Perhaps I should upgrade to the latest rails. I just don’t know – stuff that is solidly documented in the Agile development book is simply broken in the versions of rails that I run across.
Perhaps I am just down after wasting 20+ hours – first doubting myself and trying 50 ways to see if something was my fault – only to realize that it was a bug in the Rails framework.