<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lasse Bunk&#039;s weblog &#187; Flash</title>
	<atom:link href="http://lassebunk.dk/tag/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://lassebunk.dk</link>
	<description>Ruby on Rails, programming, and SEO</description>
	<lastBuildDate>Sat, 19 May 2012 10:18:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Outputting the flash to views and layouts</title>
		<link>http://lassebunk.dk/2010/03/05/outputting-the-flash-to-views-and-layouts/</link>
		<comments>http://lassebunk.dk/2010/03/05/outputting-the-flash-to-views-and-layouts/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 16:13:20 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Views]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=1177</guid>
		<description><![CDATA[How to output only the first message from the Ruby on Rails flash.]]></description>
			<content:encoded><![CDATA[<p>Here is a simple way of outputting the first message in the <a href="http://api.rubyonrails.org/classes/ActionController/Flash.html">flash</a> (because I didn&#8217;t want it to output both <code>flash[:error]</code> and <code>flash[:notice]</code> at the same time).</p>
<pre class="brush: ruby; title: ; notranslate">
# in the controller
flash[:notice] = &quot;Thanks for signing up!&quot;
</pre>
<p>.. and&#8230;</p>
<pre class="brush: ruby; title: ; notranslate">
# in the view
&lt;% flash.detect do |type, text| %&gt;
	&lt;div id=&quot;flash&quot; class=&quot;&lt;%= type.to_s %&gt;&quot;&gt;
		&lt;%= text %&gt;
	&lt;/div&gt;
&lt;% end %&gt;
</pre>
<p>The <code>detect</code> method will return the first key/value pair of the flash where the block doesn&#8217;t return <code>false</code>. However, that&#8217;s not what we&#8217;re using it for – we&#8217;re using it to make sure we only get the first element.</p>
<p>Hope this is useful.</p>
<p>
<a href="http://twitter.com/lassebunk" onclick="abtest.trackGoal(21, this);" class="icon twitter">Follow me on Twitter</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2010/03/05/outputting-the-flash-to-views-and-layouts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

