<?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>Nobody Listens Anyway &#187; ActionView::MissingTemplate</title>
	<atom:link href="http://www.justinball.com/tag/actionviewmissingtemplate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.justinball.com</link>
	<description>Life is an optimization issue</description>
	<lastBuildDate>Sat, 31 Jul 2010 16:47:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
		<item>
		<title>Stupid WTF! ActionView::MissingTemplate Exception: Missing template users/_user.erb</title>
		<link>http://www.justinball.com/2009/06/05/stupid-wtf-actionviewmissingtemplate-exception-missing-template-users_usererb/</link>
		<comments>http://www.justinball.com/2009/06/05/stupid-wtf-actionviewmissingtemplate-exception-missing-template-users_usererb/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 00:12:34 +0000</pubDate>
		<dc:creator>Justin Ball</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[ActionView::MissingTemplate]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.justinball.com/?p=1031</guid>
		<description><![CDATA[If you've spent much time working with Ruby on Rails and more especially if you've done anything with json you might have run across errors like this:

ActionView::MissingTemplate Exception: Missing template users/_user.erb

I was having this problem and doing a lot of cursing which is common when I stay up and write code until 2am which I [...]]]></description>
			<content:encoded><![CDATA[<p>If you've spent much time working with Ruby on Rails and more especially if you've done anything with json you might have run across errors like this:</p>
<pre>
ActionView::MissingTemplate Exception: Missing template users/_user.erb
</pre>
<p>I was having this problem and doing a lot of cursing which is common when I stay up and write code until 2am which I know I should do and I also know that I shouldn't write really long run on sentences but I do it anyway.</p>
<p>This error is usually the result of some code that looks like this:</p>
<pre class="ruby">&nbsp;
<span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">json</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#0066ff; font-weight:bold;">@user_html</span> = render_to_string<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> =&gt; <span style="color:#996600;">'users/user'</span>, &lt;img src=<span style="color:#996600;">'http://www.justinball.com/wp-includes/images/smilies/icon_surprised.gif'</span> alt=<span style="color:#996600;">':o'</span> <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">'wp-smiley'</span> /&gt; bject =&gt; <span style="color:#0066ff; font-weight:bold;">@user</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
  render <span style="color:#ff3333; font-weight:bold;">:json</span> =&gt; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:success</span> =&gt; <span style="color:#0000FF; font-weight:bold;">true</span>,
                              <span style="color:#ff3333; font-weight:bold;">:user_html</span> =&gt; <span style="color:#0066ff; font-weight:bold;">@user_html</span>  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;</pre>
<p>The cause of this error is that the format of the current request is :json.  There isn't an _user.json.erb template so Rails tries to find an _user.erb file.  That doesn't exist either and boom you spend the night sounding like a sailor.</p>
<p>Now I don't pretend to be an expert but I have been accused of being a hack.  I solve the problem by changing the template format:</p>
<pre class="ruby">&nbsp;
<span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">json</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#0066ff; font-weight:bold;">@template</span>.<span style="color:#9900CC;">template_format</span> = <span style="color:#ff3333; font-weight:bold;">:html</span>
  <span style="color:#0066ff; font-weight:bold;">@user_html</span> = render_to_string<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> =&gt; <span style="color:#996600;">'users/user'</span>, &lt;img src=<span style="color:#996600;">'http://www.justinball.com/wp-includes/images/smilies/icon_surprised.gif'</span> alt=<span style="color:#996600;">':o'</span> <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">'wp-smiley'</span> /&gt; bject =&gt; <span style="color:#0066ff; font-weight:bold;">@user</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
  render <span style="color:#ff3333; font-weight:bold;">:json</span> =&gt; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:success</span> =&gt; <span style="color:#0000FF; font-weight:bold;">true</span>,
                              <span style="color:#ff3333; font-weight:bold;">:user_html</span> =&gt; <span style="color:#0066ff; font-weight:bold;">@user_html</span>  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;</pre>
<p>The key is the addition of:</p>
<pre class="ruby">&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@template</span>.<span style="color:#9900CC;">template_format</span> = <span style="color:#ff3333; font-weight:bold;">:html</span>
&nbsp;</pre>
<p>Don't yell at me if it breaks.  I'm open to better suggestions but for now this does work and now my I can find other reasons to stay up late.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.justinball.com/2009/06/05/stupid-wtf-actionviewmissingtemplate-exception-missing-template-users_usererb/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
