Good notes posted by tokland
RSS feed
tokland -
June 11, 2009
4 thanks
Keeping the flash object on multiple redirects
If your controllers are redirecting more than once, the flash contents will be lost. To avoid it, execute flash.keep before each redirection.
Check ActionController::Flash::FlashHash for more handy methods (discard, now, …)
tokland -
August 20, 2008
5 thanks
Iterate and join blocks
Following LacKac’s idea, we can write render_join (useful to render a collection with a small chunks of code, where a render :partial + :spacer_template would be overkill):
def render_join(collection, join_string, &block) output = collection.collect do |item| capture(item, &block) end.join(join_string) concat(output, block.binding) end
An example of use:
<% render_join(@items, '<br />') do |item| %> <p>Item title: <%= item.title %></p> <% end %>