<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>occasionally useful</title>
	<atom:link href="http://nanodeath.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://nanodeath.wordpress.com</link>
	<description>Stuff about Ruby, Rails, and various computery things</description>
	<lastBuildDate>Thu, 27 Mar 2008 02:12:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='nanodeath.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>occasionally useful</title>
		<link>http://nanodeath.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://nanodeath.wordpress.com/osd.xml" title="occasionally useful" />
	<atom:link rel='hub' href='http://nanodeath.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Future posts</title>
		<link>http://nanodeath.wordpress.com/2008/03/26/future-posts/</link>
		<comments>http://nanodeath.wordpress.com/2008/03/26/future-posts/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 02:12:43 +0000</pubDate>
		<dc:creator>nanodeath</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nanodeath.wordpress.com/2008/03/26/future-posts/</guid>
		<description><![CDATA[Future posts will be on http://blog.maxaller.name/<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nanodeath.wordpress.com&amp;blog=3229420&amp;post=9&amp;subd=nanodeath&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Future posts will be on <a href="http://blog.maxaller.name/">http://blog.maxaller.name/</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nanodeath.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nanodeath.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nanodeath.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nanodeath.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nanodeath.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nanodeath.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nanodeath.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nanodeath.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nanodeath.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nanodeath.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nanodeath.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nanodeath.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nanodeath.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nanodeath.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nanodeath.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nanodeath.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nanodeath.wordpress.com&amp;blog=3229420&amp;post=9&amp;subd=nanodeath&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nanodeath.wordpress.com/2008/03/26/future-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/250b3c601cbd646bece3d2464b024488?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nanodeath</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamic Methods in Ruby</title>
		<link>http://nanodeath.wordpress.com/2008/03/25/dynamic-methods-in-ruby/</link>
		<comments>http://nanodeath.wordpress.com/2008/03/25/dynamic-methods-in-ruby/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 03:40:44 +0000</pubDate>
		<dc:creator>nanodeath</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://nanodeath.wordpress.com/?p=8</guid>
		<description><![CDATA[So this was sort of hard even if it doesn&#8217;t look like it, but I found out how to do dynamic methods and whatnot. Put this in your class. def self.my_method(takes, two) define_method &#8220;cool_&#8221;+takes do &#124;arg&#124; puts two + arg end end The &#8220;method generator&#8221; takes two arguments, and the method itself takes just one. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nanodeath.wordpress.com&amp;blog=3229420&amp;post=8&amp;subd=nanodeath&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So this was sort of hard even if it doesn&#8217;t look like it, but I found out how to do dynamic methods and whatnot.  Put this in your class.</p>
<p>def self.my_method(takes, two)<br />
define_method &#8220;cool_&#8221;+takes do |arg|<br />
puts two + arg<br />
end<br />
end</p>
<p><span id="more-8"></span></p>
<p>The  &#8220;method generator&#8221; takes two arguments, and the method itself takes just one.  The generator creates a new method that can be called by prefixing whatever the first argument was with cool_, and the generated method prints out the second &#8220;method generator&#8221; argument followed by whatever the argument to the generated method was.<br />
Output:</p>
<p>&gt;&gt; S.class.my_method &#8220;cat&#8221;, &#8220;silly &#8220;<br />
=&gt; #&lt;Proc:0xb7639fb8@/home/stuff/file.rb:30&gt;<br />
&gt;&gt; S.cool_cat &#8220;goose&#8221;<br />
silly goose<br />
=&gt; nil</p>
<p>Not too bad, is it?</p>
<p>Note that &#8220;self&#8221; is required because instances don&#8217;t have access to define_method, but the classes do&#8230;or something.  Anyway, experiment with it a bit <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Obviously, this can (and should) be adapted for mixins.  Lastly, one could/should replace &#8220;S.class&#8221; with whatever the class of S is, when typing it in.  I was doing this in an attempt to make a custom accessor until I realized I&#8217;d spent the last hour generalizing for a case in which there were 3 lines of code.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nanodeath.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nanodeath.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nanodeath.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nanodeath.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nanodeath.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nanodeath.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nanodeath.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nanodeath.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nanodeath.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nanodeath.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nanodeath.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nanodeath.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nanodeath.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nanodeath.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nanodeath.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nanodeath.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nanodeath.wordpress.com&amp;blog=3229420&amp;post=8&amp;subd=nanodeath&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nanodeath.wordpress.com/2008/03/25/dynamic-methods-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/250b3c601cbd646bece3d2464b024488?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nanodeath</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple Easy AJAX Form Validation in Rails</title>
		<link>http://nanodeath.wordpress.com/2008/03/24/simple-easy-ajax-form-validation-in-rails/</link>
		<comments>http://nanodeath.wordpress.com/2008/03/24/simple-easy-ajax-form-validation-in-rails/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 06:27:19 +0000</pubDate>
		<dc:creator>nanodeath</dc:creator>
				<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://nanodeath.wordpress.com/?p=7</guid>
		<description><![CDATA[I&#8217;m using Ruby 1.8 and Rails 2 for this. Thanks to BigSmoke for both the ActiveResource::Errors hint as well as inspiring me to look for another way. What this method does is create and populate an error div with the specific error messages that occurred, and then destroy the div when the user submits a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nanodeath.wordpress.com&amp;blog=3229420&amp;post=7&amp;subd=nanodeath&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using Ruby 1.8 and Rails 2 for this.</p>
<p>Thanks to <a href="http://www.bigsmoke.us/ajax-validation-on-rails/" target="_blank">BigSmoke</a> for both the ActiveResource::Errors hint as well as inspiring me to look for another way.</p>
<p>What this method does is create and populate an error div with the specific error messages that occurred, and then destroy the div when the user submits a valid entry.<br />
<span id="more-7"></span><br />
You&#8217;ll need three files: a controller, an rjs, and a partial.</p>
<p>Also there are Pastebin links to prettier and generally better code demonstration (no cutoff, syntax highlighting)</p>
<p><b>Controller</b>:</p>
<p>The way I have it set up, the controller invokes the same rjs file regardless of success or failure.  This minimizes the number of files needed and isn&#8217;t too inconvenient.  I simply added a @error = true to the branch of the failure, like so.  <a href="http://pastebin.com/f6f8b55cd" target="_blank">Pastebin link</a>.</p>
<pre>
def create
	@myobject = Myobject.new(params[:myobject])
	@myobject.metagame_id = @id
	respond_to do |format|
		if @myobject.save
			flash[:notice] = 'Myobject was successfully created.'
			format.html { redirect_to myobject_url(@myobject) }
			format.xml  { head :created, :location =&gt; myobject_url(@myobject) }
			format.js { render :action=&gt; 'create' }
		else
			@error = true
			format.html { render :action =&gt; "new" }
			format.xml  { render <img src='http://s2.wp.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml =&gt; @myobject.errors.to_xml }
			format.js { render :action =&gt; 'create' }
		end
	end
end</pre>
<p><b>RJS</b>:</p>
<p>This one happens to be named &#8216;create&#8217;.  I have different behaviors set up for whether error is set or not.  A flash variable is used to track the error state.  A partial is loaded in each case.  Also, I should mention that the id of the remote_form_for this is going in is ajax_create.  <a href="http://pastebin.com/f6c59dc44" target="_blank">Pastebin version</a>.</p>
<pre>
if @error.nil?
	page.insert_html :bottom, 'myobject_container',{:partial=&gt;'myobject_row', <img src='http://s1.wp.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> bject=&gt;@myobject}
	page.visual_effect :highlight, "myobject_container", :duration=&gt;2
	if flash[:create_form_error]
		# Cleanup
		page.remove 'form_error'
	end
else
	# Was there already an error?
	if flash[:create_form_error]
		# Update old error message
		page.replace 'form_error', :partial=&gt;'form_error', <img src='http://s1.wp.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> bject=&gt;@myobject
	else
		# Create error dialog
		page.insert_html :top, 'ajax_create', {:partial=&gt;'form_error', <img src='http://s1.wp.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> bject=&gt;@myobject}
	end

	flash[:create_form_error] = true
	page.visual_effect :highlight, 'form_error', :duration=&gt;2
end</pre>
<p><b>Partial</b>:</p>
<p>This partial&#8217;s filename is _form_error.html.erb.  I think its contents are fairly self-explanatory.  <a href="http://pastebin.com/fa34cd97" target="_blank">Pastebin link</a>.</p>
<pre>
&lt;div id='form_error'&gt;There were one or more errors.
	&lt;ul&gt;
	&lt;% form_error.errors.each_full do |msg| %&gt;
		&lt;li&gt;&lt;%=msg%&gt;&lt;/li&gt;
	&lt;% end %&gt;
	&lt;/ul&gt;
&lt;/div&gt;</pre>
<p><b>Bonus</b>: CSS</p>
<p>In case you&#8217;re curious, the CSS I used was this:</p>
<pre>
#form_error {
background:pink;
border:4px solid red;
padding:4px;
margin:2px;
}</pre>
<p>Hope this helps.  If you found it useful, noticed something I left out, or would like to comment for any reason, please do!  At least to inspire me to do future tutorials.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nanodeath.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nanodeath.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nanodeath.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nanodeath.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nanodeath.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nanodeath.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nanodeath.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nanodeath.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nanodeath.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nanodeath.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nanodeath.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nanodeath.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nanodeath.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nanodeath.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nanodeath.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nanodeath.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nanodeath.wordpress.com&amp;blog=3229420&amp;post=7&amp;subd=nanodeath&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nanodeath.wordpress.com/2008/03/24/simple-easy-ajax-form-validation-in-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/250b3c601cbd646bece3d2464b024488?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nanodeath</media:title>
		</media:content>
	</item>
	</channel>
</rss>
