Overriding Form Theme of a Collection (Symfony2)


This code was floating around in a pastebin, and was linked to me from IRC. I’m not sure who originally wrote it, but it’s useful and I wanted to make sure it gets saved so that it can eventually be the basis of a Symfony2 cookbook article.

[code lang="php"]{% block collection_widget %}
{% spaceless %}
<div class="collection">
{% if prototype is defined %}
{% set attr = attr|merge({'data-prototype': block('collection_item_widget') }) %}
{% endif %}
<div {{ block('widget_container_attributes') }}>
{{ form_errors(form) }}
<ul>
{% for rows in form %}
<li>
{% set fieldNum = 1 %}
{% for row in rows %}
<div class="field{{ fieldNum }}">
{{ form_label(row) }}
{{ form_widget(row, { 'attr': { 'class': 'test' }}) }}
</div>
{% set fieldNum = fieldNum + 1 %}
{% endfor %}
<a class="remove" title="Remove" href="javascript:void()">
<span>Delete</span>
</a>
<div class="clear"></div>
</li>
{% endfor %}
</ul>
{{ form_rest(form) }}
</div>
<div class="clear"></div>
<a class="add" title="Add" href="javascript:void()">
<div style="display: none;"></div>
<span>Add</span>
</a>
</div>
<div class="clear"></div>
{% endspaceless %}
{% endblock collection_widget %}

{% block collection_item_widget %}
{% spaceless %}
<li>
{% set fieldNum = 1 %}
{% for row in prototype %}
<div class="field{{ fieldNum }}">
{{ form_label(row) }}
{{ form_widget(row, { 'attr': { 'class': 'test' }}) }}
</div>
{% set fieldNum = fieldNum + 1 %}
{% endfor %}
<a class="remove" title="Remove" href="javascript:void()">
<span>Delete</span>
</a>
<div class="clear"></div>
</li>
{% endspaceless %}
{% endblock collection_item_widget %}[/code]

Also, here’s a github gist link to the same code.

Updating RubyGems on OS X Leopard


Sorry for the long hiatus from the blog, I’ve recently been quite busy at work with one particularly important project scheduled for an early December launch.

More than one of these projects now utilizes the Symfony2 PHP framework, and in addition to that we’ve been using “Capifony”, a deployment recipe which Capistrano utilizes to deploy Symfony or Symfony2 sites.

Usually, on my home machines I use Ubuntu linux, which I’m pretty happy with. Setting up an up-to-date version of Apache, MySQL, Ruby, Capistrano and PHP (with the intl module, importantly, since this is required by Symfony) is made very easy with the use of the apt-get or aptitude package managers.

Unfortunately, my experience with OS X (which I nevertheless like as an operating system) has not been as much of a smooth sailing kind of thing.

One recent issue I’ve run into is that when setting up capistrano to deploy our Symfony app on this older version of OS X, the gem app is too out of date to even know where to get the update package from to update itself (v1.0.1).

Figuring out how to update RubyGems was quick and relatively painless, but the instructions given by multiple sites that popped up on Google were flat out wrong. So… I’m taking the opportunity to document it here.

Updating RubyGems from Version 1.0.1 On OS X Leopard

The first step I tried was…
$ sudo gem update --system

This is what you would normally use, however, v1.0.1 attempts to fetch from the wrong source.

This was the error returned:
ERROR: While executing gem ... (Gem::RemoteSourceException)
HTTP Response 302 fetching http://gems.rubyforge.org/yaml

What finally worked was this:

$ sudo gem update --system --source http://production.s3.rubygems.org/

We’re at 1.3.6. As simple as that.

The following was the first result on Google and did not work for whatever reason…

gem install rubygems-update --source http://production.s3.rubygems.org/
update_rubygems