<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Web Producer - Singer - Photography - MBHNYC</title>
	
	<link>http://www.matthewhensrud.net</link>
	<description />
	<lastBuildDate>Thu, 19 Jan 2012 22:34:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/mbhnyc" /><feedburner:info uri="mbhnyc" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>On Seeding Nested Models in Rails 3</title>
		<link>http://feedproxy.google.com/~r/mbhnyc/~3/n5gT2uoaLRQ/</link>
		<comments>http://www.matthewhensrud.net/2011/blog/on-seeding-nested-models-in-rails-3/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 19:28:43 +0000</pubDate>
		<dc:creator>mhensrud</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[models]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.matthewhensrud.net/?p=156</guid>
		<description><![CDATA[So you&#8217;re in active development and want some real-ish data in your app, eh?  And you keep making adjustments to your model as you understand the requirements better?  Oh?  Your models are deeply nested, like a proper associative-normalizing ninja?   So I was struggling mightily with this, and couldn&#8217;t find any tutorials that gave me [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><img class="alignleft" src="http://www.matthewhensrud.net/wp-content/uploads/2011/08/ninja_assassin1-286x300.jpg" alt="Dead Models" width="230" style="bottom-margin:30px"/></p>
<p>So you&#8217;re in active development and want some real-ish data in your app, eh?  And you keep making adjustments to your model as you understand the requirements better?  Oh?  Your models are deeply nested, like a proper associative-normalizing ninja?  </p>
<p><span id="more-156"></span></p>
<p>So I was struggling mightily with this, and couldn&#8217;t find any tutorials that gave me the key.  Here were my (non operational) models (simplified for this post):</p>
<p>
<pre class="brush: ruby; title: ; notranslate">
class User &lt; ActiveRecord::Base
  attr_accessible :email, :password, :password_confirmation
  has_many :surveys
  accepts_nested_attributes_for :surveys
end
</pre>
</p>
<p>and</p>
<p>
<pre class="brush: ruby; title: ; notranslate">
class Survey &lt; ActiveRecord::Base
  belongs_to :user
  attr_accessible :name, :active
end
</pre>
</p>
<p>So now you want to see these with a sample user + survey? Should be easy right,</p>
<pre>accepts_nested_attributes_for</pre>
<p>is set! I expected this would work:</p>
<p>
<pre class="brush: ruby; title: ; notranslate">
params = { :u =&gt; {
  :email =&gt; &quot;me@awesome.com&quot;, :password =&gt; &quot;guessthishackers&quot;, :surveys_attributes =&gt; [
          { :name =&gt; 'Test Survey', :active =&gt; true}
        ]
        }}
person = User.create(params[:u])
</pre>
</p>
<p>No dice. Fails with a &#8220;can&#8217;t mass-assign error&#8221; in the development log. A great deal of searching didn&#8217;t provide an obvious answer, but points clearly to the model. After a fair amount of googling and head scratching, the answer hit me like a brick:</p>
<p>
<pre class="brush: ruby; title: ; notranslate">
attr_accessible :surveys_attributes
</pre>
</p>
<p>Duh, the attributes hash is a first-level attribute of User, in-and-of-itself!</p>
<p>Moral of the story — seeds.rb is a ruby file that mass-assigns for breakfast. Tweak your models accordingly.</p>
<div class="shr-publisher-156"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fwww.matthewhensrud.net%2F2011%2Fblog%2Fon-seeding-nested-models-in-rails-3%2F' data-shr_title='On+Seeding+Nested+Models+in+Rails+3'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fwww.matthewhensrud.net%2F2011%2Fblog%2Fon-seeding-nested-models-in-rails-3%2F' data-shr_title='On+Seeding+Nested+Models+in+Rails+3'></a><a class='shareaholic-tweetbutton' data-shr_count='horizontal' data-shr_href='http%3A%2F%2Fwww.matthewhensrud.net%2F2011%2Fblog%2Fon-seeding-nested-models-in-rails-3%2F' data-shr_title='On+Seeding+Nested+Models+in+Rails+3'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.matthewhensrud.net/2011/blog/on-seeding-nested-models-in-rails-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.matthewhensrud.net/2011/blog/on-seeding-nested-models-in-rails-3/</feedburner:origLink></item>
		<item>
		<title>On detecting idle states in Flex 4</title>
		<link>http://feedproxy.google.com/~r/mbhnyc/~3/RgqrLNBsSBM/</link>
		<comments>http://www.matthewhensrud.net/2010/flex/on-detecting-idle-states-in-flex-4/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 16:37:59 +0000</pubDate>
		<dc:creator>mhensrud</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[idle]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.matthewhensrud.net/?p=90</guid>
		<description><![CDATA[So I&#8217;m building a B2B dashboard in Flex, and thought I&#8217;d write up a quick post on a problem I didn&#8217;t see many online solutions for &#8211; well, there are solutions, but they all reference weaksauce flex 2, so I thought I&#8217;d go all new and shiny and post this working flex 4 example. The [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>So I&#8217;m building a B2B dashboard in Flex, and thought I&#8217;d write up a quick post on a problem I didn&#8217;t see many online solutions for &#8211; well, there are solutions, but they all reference weaksauce flex 2, so I thought I&#8217;d go all new and shiny and post this working flex 4 example.</p>
<p>The problem is simple: How do I detect an Idle user, turn off all timed network requests, and — eventually — log off users silly enough to walk away from my interface?</p>
<div id="attachment_91" class="wp-caption alignnone" style="width: 310px"><br />
<img src="http://www.matthewhensrud.net/wp-content/uploads/2010/07/Bored-Computer-User-300x207.jpg" alt="An idle user" title="Idle User" width="300" height="207" class="size-medium wp-image-91" /><br />
<p class="wp-caption-text">Example: situation this code is meant to save my application from.</p></div>
<p><span id="more-90"></span></p>
<p>So Here&#8217;s a somewhat disjointed code sample.  This isn&#8217;t a working application, and is missing a few helper functions, and, uh, any interactivity whatsoever &#8211; but should get anyone where they need to go.</p>
<p>Tada:</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>?xml version<span class="sy0">=</span><span class="st0">&quot;1.0&quot;</span> encoding<span class="sy0">=</span><span class="st0">&quot;utf-8&quot;</span><span class="kw2">?&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>s<span class="sy0">:</span>Application xmlns<span class="sy0">:</span>fx<span class="sy0">=</span><span class="st0">&quot;http://ns.adobe.com/mxml/2009&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; xmlns<span class="sy0">:</span>s<span class="sy0">=</span><span class="st0">&quot;library://ns.adobe.com/flex/spark&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; xmlns<span class="sy0">:</span>mx<span class="sy0">=</span><span class="st0">&quot;library://ns.adobe.com/flex/mx&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; mouseMove<span class="sy0">=</span><span class="st0">&quot;application_mouseMoveHandler(event)&quot;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sy0">&lt;</span>fx<span class="sy0">:</span>Script<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sy0">&lt;!</span><span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">public</span> <span class="kw2">var</span> idleCounter<span class="sy0">:</span>int<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">public</span> <span class="kw2">var</span> sysMan<span class="sy0">:</span>ISystemManager<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">public</span> <span class="kw2">var</span> secondsSinceIdle<span class="sy0">:</span>int <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//create your timer objects to do, you know, stuff. Below, a function called timer_short</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">//this is my function for handling grabbing a user after a successful login</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;protected <span class="kw2">function</span> getUserByIDResult_resultHandler<span class="br0">&#40;</span>event<span class="sy0">:</span>ResultEvent<span class="br0">&#41;</span><span class="sy0">:</span>void</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; sysMan <span class="sy0">=</span> FlexGlobals<span class="sy0">.</span>topLevelApplication<span class="sy0">.</span>systemManager<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; sysMan<span class="sy0">.</span>addEventListener<span class="br0">&#40;</span>FlexEvent<span class="sy0">.</span>IDLE<span class="sy0">,</span> userIdle<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; session<span class="sy0">.</span>user <span class="sy0">=</span> event<span class="sy0">.</span>result <span class="kw1">as</span> User<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; timer<span class="sy0">.</span>addEventListener<span class="br0">&#40;</span>TimerEvent<span class="sy0">.</span>TIMER<span class="sy0">,</span> timer_short<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; timer<span class="sy0">.</span>start<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; currentState<span class="sy0">=</span><span class="st0">&#39;Main&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">private</span> <span class="kw2">function</span> userIdle<span class="br0">&#40;</span>e<span class="sy0">:</span>FlexEvent<span class="br0">&#41;</span><span class="sy0">:</span>void <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; idleCounter<span class="sy0">++;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; trace<span class="br0">&#40;</span>idleCounter<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>idleCounter <span class="sy0">&gt;</span> <span class="nu0">100</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;secondsSinceIdle <span class="sy0">+=</span> <span class="nu0">10</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;idleCounter <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>secondsSinceIdle <span class="sy0">&gt;</span> <span class="nu0">60</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; trace<span class="br0">&#40;</span><span class="st0">&quot;idle longer than 1 minute&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>timer<span class="sy0">.</span>hasEventListener<span class="br0">&#40;</span>TimerEvent<span class="sy0">.</span>TIMER<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;timer<span class="sy0">.</span>removeEventListener<span class="br0">&#40;</span>TimerEvent<span class="sy0">.</span>TIMER<span class="sy0">,</span> timer_short<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>secondsSinceIdle <span class="sy0">&gt;</span> <span class="nu0">180</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; trace<span class="br0">&#40;</span><span class="st0">&quot;idle longer than 3 minutes&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; sysMan<span class="sy0">.</span>removeEventListener<span class="br0">&#40;</span>FlexEvent<span class="sy0">.</span>IDLE<span class="sy0">,</span> userIdle<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; session<span class="sy0">.</span>user <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; currentState<span class="sy0">=</span><span class="st0">&#39;Login&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; Alert<span class="sy0">.</span>show<span class="br0">&#40;</span><span class="st0">&quot;You have been logged out due to laziness and despondency.&quot;</span><span class="sy0">,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;Alert&quot;</span><span class="sy0">,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;Alert<span class="sy0">.</span>OK<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;protected <span class="kw2">function</span> application_mouseMoveHandler<span class="br0">&#40;</span>event<span class="sy0">:</span>MouseEvent<span class="br0">&#41;</span><span class="sy0">:</span>void</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; secondsSinceIdle <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; idleCounter <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>timer<span class="sy0">.</span>hasEventListener<span class="br0">&#40;</span>TimerEvent<span class="sy0">.</span>TIMER<span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span> session<span class="sy0">.</span>user <span class="sy0">!=</span> <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;timer<span class="sy0">.</span>addEventListener<span class="br0">&#40;</span>TimerEvent<span class="sy0">.</span>TIMER<span class="sy0">,</span> timer_short<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sy0">&lt;/</span>fx<span class="sy0">:</span>Script<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>s<span class="sy0">:</span>Application<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Also, thanks to <a href="http://www.rlmseo.com/blog/read-more-link-on-wordpress-pages/">Razorlight</a> for some WordPress assistance getting this page to appear correctly.</p>
<div class="shr-publisher-90"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fwww.matthewhensrud.net%2F2010%2Fflex%2Fon-detecting-idle-states-in-flex-4%2F' data-shr_title='On+detecting+idle+states+in+Flex+4'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fwww.matthewhensrud.net%2F2010%2Fflex%2Fon-detecting-idle-states-in-flex-4%2F' data-shr_title='On+detecting+idle+states+in+Flex+4'></a><a class='shareaholic-tweetbutton' data-shr_count='horizontal' data-shr_href='http%3A%2F%2Fwww.matthewhensrud.net%2F2010%2Fflex%2Fon-detecting-idle-states-in-flex-4%2F' data-shr_title='On+detecting+idle+states+in+Flex+4'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.matthewhensrud.net/2010/flex/on-detecting-idle-states-in-flex-4/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://www.matthewhensrud.net/2010/flex/on-detecting-idle-states-in-flex-4/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 5.892 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-02-06 00:40:37 -->

