Skip to content

Instantly share code, notes, and snippets.

@adamhjk
Created April 8, 2009 21:15
Show Gist options
  • Save adamhjk/92045 to your computer and use it in GitHub Desktop.
Save adamhjk/92045 to your computer and use it in GitHub Desktop.
###
# Fragile, embedded, deeply tied
###
<% search("foo").each do |n| -%>
stuff with <%= n %>
<% end %>
###
# Less fragile, not embedded
# In a recipe
###
foo_servers = search("foo")
template "foo" do
variables(
:foo_servers => foo_servers
)
end
# In your template
<% @foo_servers.each do |n| -%>
stuff with <%= n %>
<% end %>
# The advantage of the latter is that you can now change what @foo_servers contains
# at your whim. You could also pass foo_servers around to N different templates, each
# one doing something different with the data. ie: if you had two templates that both
# need foo_servers, you simply pass the reference to foo_servers around.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment