Get updates

Archive for January, 2007

Scott Passing :id When Rendering a Component

For the time being I’ve decided to forgo acts_as_tree and roll my own solution for nested list display. At this point I don’t think I really need to parse and display the entire tree in one fell swoop, it seems more natural to display the top level and retrieve children of a node when the user clicks and expands the node.

Since my “list” action has been doing fine to display list items, I quickly made it context-aware and used it as a component to render the children of a node when an item is expanded. Consulting my rails book I tried to render like this:

Continue Reading…

Scott Displaying a hierarchy and acts_as_tree

What’s brewing over at ListFinity, home of infinite lists?

Well, supposedly right now I’m working out various means of constructing and manipulating “infinitely nestable” lists, as in an object hierarchy (aka tree view) of arbitrary depth.

That’s all well and good, but not as straightforward to code as the display of a single unordered list. I figured that such a hierarchy would be a good candidate for recursion, and in this case that didn’t sound like too big a chore to write… except when I started to imagine that each loop back to the recursive method would want to pass on the list data for the next loop to walk through another level, etc. This triggered a flash of nightmares where a sufficiently large or deep list (nevermind one mangled to include circular references) spurs the recursion on to eat memory like a mosquito with its proboscis stuck in the jugular.

Continue Reading…

Scott Q&A: How to Set a Form’s ID in Rails?

HTML is not hard. Anyone who can program, in any language, should be able to write HTML with little or no training. Yet there are reasons why the HTML helper functions in Rails can be handy. Chief among them is the easy and fairly clean way you can incorporate variables and other constructs; after all, the idea here is to have an app generate some of the code rather than having to write every piece by hand.

I was happily marching to the tune of form_tag() when I decided that I wanted a little JavaScript function to interact with the form’s contents. Great, except the HTML form code being generated by that helper function wasn’t coming with its own id attribute.

I could probably have the JavaScript function refer to this particular form by indexing an array, but then it could break if I ever changed the layout of the page to include another form. Hardly ideal.

Question: How does one tell Rails what the form’s id should be when creating the form with the helper function (or the Ajax form_remote_tag)?

Continue Reading…

3DM Design is where Scott Drake publishes thoughts on programming web applications in JavaScript and Ruby.