Displaying articles with tag

Using the Switchtower "put" helper

Posted by admin, Mon Jan 16 08:51:20 UTC 2006

It would be really nice if the “put” helper worked as advertised.  Unfortunately, when I used it today, I ran into an annoying problem.  The destination file already existed, and it’s size was larger than the source file.  So what I got was a munged file that started with the source file contents, and ended with leftover crap from the original destination file.  This was definitely not what I intended. 

It is an easy enough problem to work around.  One uses the “delete” helper on the original destination file, first. 

SwitchTower: Automating Application Deployment |

The put helper let’s you transfer data from the local host to a file on the remote host. In this case, though, the file is transferred to all associated servers via a single call to put. If Net::SFTP is available, it will be used to transfer the files, otherwise a less-robust method is used (pipe to cat).

1 comment | Filed Under: | Tags:

Calgary Ruby Users Society

Posted by admin, Wed Jan 11 09:40:31 UTC 2006

Tim Breitkreutz and I are starting a Ruby user group here in Calgary. If you are interested in attending, please leave a comment, including the number of people who plan to attend. We have a small boardroom lined up, but if the numbers get out of hand we will have to go begging for space elsewhere.

CRUSERS – Calgary Ruby Users Society

CRUSERS is the home of the Calgary Ruby USERs Society. The inaugural meeting will be held on Feb 21, 2006.

10 comments | Filed Under: | Tags:

Tightening up Drag & Drop

Posted by admin, Wed Nov 30 11:57:16 UTC 2005

I was trying to implement a drag and drop list in my RoR web application, using the shopping cart demo from script.aculo.us as a template.  But there was one problem.  When I added and removed items from my "list", the entire list was rendered.  In my case, this was worse than inefficient, since some of the "items" dropped into the list needed to be set up using calls to the database.

Now, in the excellent Agile Web Development with Rails book, in Chapter 18, they describe a method of "Dynamically Updating a List", which pretty much did what I wanted, which is just add or remove an "item" from my "list", only updating the item in question.  No drag and drop, though.

The problem was figuring out how to combine these two examples into something that worked.  The solution, as always in RoR, is almost childishly simple to implement, but I spent most of an afternoon figuring out those elegant, simple, 4 lines of code… :-}

In the interests of saving others that afternoon of fiddling, I figured I should post my solution.  I’m simplifying things here.  We are dealing with a simple "list" which contains "items", and when we drag an item into the list it gets added, and when we drag an item out of the list it gets removed.  I’m not "counting" products like in the actual shopping cart demo.

For the drop_receiving element "list", add a position parameter, like:

:position => :top,

Then, in the add method, instead of:

render :partial => 'list'

use:

render :partial => 'list', :object => item

And in your remove method, instead of:

render :partial => 'list'

use:

render :inline => "Element.remove('item_#{i}');"

And for your drop_receiving_element "trash", change:

:complete => "Element.hide('indicator')"

to

:complete => "eval(request.responseText);Element.hide('indicator')"

Simple, eh?  Hopefully I’ll soon have an external RoR server where I can post a working version with complete source.

0 comments | Filed Under: | Tags: