Archive for October, 2008

ruby on rails - has and belongs to many view plugin

So I’ll never have to write another has_and_belongs_to_many view again, here’s a plugin that dynamically makes 2 <ul> lists which you drag and drop both ways to manage the association.

http://svn.ahabman.com/public/many_to_many_view/

From the readme:

Assumming you have an @project var and you want to associate people with it.

<div id="m2m_container">
<%= render :partial => "shared/m2m", :locals => {
:thing => @project,
:association => 'people',
:association_attr => 'first_name' }   %>
</div>

:thing take the current object
:association takes the pluralized association, a string.
:association_attr takes the attribute of the associated object that will be displayed.

You can’t use class variables in rails.

You can’t use class variables in rails.  Unless you’d like to develop in production mode (specifically with config.cache_classes = true).  In development mode all classes are reloaded on each request, which clears all class variables.

I had the perfect place to use them - while running a mass synchronization, and needing to store the timestamp (I couldn’t use the latest last_updated from each record).  It worked perfect in ./script/console but failed entirely through the browser.