<?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>ELEVATION Dev Blog &#187; tips</title>
	<atom:link href="http://dev.elevationblog.com/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.elevationblog.com</link>
	<description></description>
	<lastBuildDate>Wed, 06 Oct 2010 21:07:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>refinerycms-blog: comments with DISQUS</title>
		<link>http://dev.elevationblog.com/2010/04/08/refinerycms-blog-comments-with-disqus/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=refinerycms-blog-comments-with-disqus</link>
		<comments>http://dev.elevationblog.com/2010/04/08/refinerycms-blog-comments-with-disqus/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 00:19:25 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[tips]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://dev.elevationblog.com/?p=1614</guid>
		<description><![CDATA[For adding a blog to your refinery site, there&#8217;s pretty much only one option: the refinerycms-blog plugin. Fortunately like most refinery things, it&#8217;s pretty easy to customize. I wanted to use DISQUS to moderate the comments on this particular blog, and here&#8217;s how I did it (You obviously need a DISQUS account to do this).  [...]]]></description>
			<content:encoded><![CDATA[<p>For adding a blog to your refinery site, there&#8217;s pretty much only one option: the <a href="http://github.com/unixcharles/refinerycms-blog" target="_blank">refinerycms-blog plugin</a>. Fortunately like most refinery things, it&#8217;s pretty easy to customize.</p>
<p>I wanted to use <a href="http://disqus.com">DISQUS</a> to moderate the comments on this particular blog, and here&#8217;s how I did it (You obviously need a DISQUS account to do this).  If a file referred to doesn&#8217;t exist, copy it from vendor/plugins/app/views/blogs to your theme directory.</p>
<ol>
<li><strong>Remove the old comment form:<br />
themes/mysite/views/blogs/show.html.erb</strong><br />
remove the render &#8220;_form&#8221; line since we don&#8217;t need a comment form anymore</li>
<li><strong>Add the Disqus embed code<br />
themes/mytheme/views/blogs/_comments.html.erb</strong><br />
Replace everything in this file with the disqus embed code, replace mysite below with your disqus shortname.</p>
<pre class="brush: plain">&lt;div id='comments'&gt;
 &lt;div id="disqus_thread"&gt;&lt;/div&gt;
 &lt;script type="text/javascript"&gt;
 var disqus_identifier = "&lt;%= @blog.permalink %&gt;";
 &lt;%= "var disqus_developer = 1;" if local_request? %&gt;

 (function() {
 var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
 dsq.src = 'http://mysite.disqus.com/embed.js';
 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
 })();
 &lt;/script&gt;
 &lt;noscript&gt;Please enable JavaScript to view the &lt;a href="http://disqus.com/?ref_noscript=mysite"&gt;comments powered by Disqus.&lt;/a&gt;&lt;/noscript&gt;
&lt;/div&gt;</pre>
</li>
<li><strong>Add the disqus comment counter code<br />
/themes/mysite/views/blogs/index.html.erb<br />
</strong><br />
Change line 16 to:</p>
<pre class="brush: plain">
  <%= link_to 'Read more', blog_post_url(blog.permalink)+"#disqus_thread" -%>
</pre>
<p>Put this somewhere near the bottom:</p>
<pre class="brush: plain">&lt;% content_for :footer do -%&gt;
 &lt;script type="text/javascript"&gt;
 //&lt;![CDATA[
 (function() {
 var links = document.getElementsByTagName('a');
 var query = '?';
 for(var i = 0; i &lt; links.length; i++) {
 if(links[i].href.indexOf('#disqus_thread') &gt;= 0) {
 query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&amp;';
 }
 }
 document.write('&lt;script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/poetrybooths/get_num_replies.js' + query + '"&gt;&lt;/' + 'script&gt;');
 })();
 //]]&gt;
 &lt;/script&gt;
&lt;% end -%&gt;</pre>
<p><strong>/themes/mysite/views/shared/_footer.html.erb<br />
</strong>add &lt;%= yield :footer %&gt; to your footer file so our comment counter javascript gets placed there.</li>
</ol>
<p>Pretty easy.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.elevationblog.com/2010/04/08/refinerycms-blog-comments-with-disqus/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>refinerycms _blank target nav</title>
		<link>http://dev.elevationblog.com/2010/04/07/refinerycms-_blank-target-nav/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=refinerycms-_blank-target-nav</link>
		<comments>http://dev.elevationblog.com/2010/04/07/refinerycms-_blank-target-nav/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 19:23:37 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[tips]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[refinery]]></category>
		<category><![CDATA[refinerycms]]></category>

		<guid isPermaLink="false">http://dev.elevationblog.com/?p=1609</guid>
		<description><![CDATA[Recently I&#8217;ve been evaluating refinerycms for a few client projects that it seemed suited for, and I really like that while it&#8217;s not always 100% what I want, it&#8217;s very easy to modify to get it to where I need it. Here&#8217;s an example: My site needs a main nav to link offsite in a [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been evaluating <a href="http://refinerycms.com">refinerycms</a> for a few client projects that it seemed suited for, and I really like that while it&#8217;s not always 100% what I want, it&#8217;s very easy to modify to get it to where I need it.</p>
<p>Here&#8217;s an example: My site needs a main nav to link offsite in a new window by adding target=&#8221;_blank&#8221; to the link, which is not handled out of the box by refinery.  So I copied vendor/refinery/app/views/shared/_menu_branch.html.erb into my theme directory to override the functionality and modified line 11 to the following:</p>
<pre>&lt;%= link_to menu_branch.title, menu_branch.url, \
:target =&gt; menu_branch.url.include?("http://") ? "_blank" : "" %&gt;
</pre>
<p>Now any link containing http:// is automatically given a blank target. Presto.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.elevationblog.com/2010/04/07/refinerycms-_blank-target-nav/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>validate image dimensions with paperclip</title>
		<link>http://dev.elevationblog.com/2009/01/31/validate-image-dimensions-with-paperclip/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=validate-image-dimensions-with-paperclip</link>
		<comments>http://dev.elevationblog.com/2009/01/31/validate-image-dimensions-with-paperclip/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 02:48:00 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[paperclip]]></category>

		<guid isPermaLink="false">http://elevationblog.com/2009/01/31/validate-image-dimensions-with-paperclip</guid>
		<description><![CDATA[I’m liking paperclip, in a recent project I chose it specifically because it buffers writes on uploads, which should help keep memory usage down. I needed to validate that an uploaded image was at least a certian size, and it was a little tricky, but here’s what I came up with: has_attached_file :image, :styles =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I’m liking <a href="http://www.thoughtbot.com/projects/paperclip">paperclip</a>, in a recent project I chose it specifically because it buffers writes on uploads, which should help keep memory usage down.</p>
<p>I needed to validate that an uploaded image was at least a certian size, and it was a little tricky, but here’s what I came up with:</p>
<pre class="brush: ruby">
 has_attached_file :image,
                   :styles =&gt; { :original =&gt; ["1000x600&gt;", :jpg]},
                   :whiny_thumbnails =&gt; true

 def validate
    dimensions = Paperclip::Geometry.from_file(self.image.queued_for_write[:original])
    self.errors.add(:image, "Please upload a file at least 700 pixels wide") if dimensions.width &lt; 700
    self.errors.add(:image, "Please upload a file at least 200 pixels tall") if dimensions.height &lt; 200
  end</pre>
<p>like it? hate it? have something better?</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.elevationblog.com/2009/01/31/validate-image-dimensions-with-paperclip/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>rspec+rcov = segfault death</title>
		<link>http://dev.elevationblog.com/2008/11/14/rspec-rcov-segfault-death/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rspec-rcov-segfault-death</link>
		<comments>http://dev.elevationblog.com/2008/11/14/rspec-rcov-segfault-death/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 23:25:00 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[gotchas]]></category>
		<category><![CDATA[rcov]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://elevationblog.com/2008/11/14/rspec-rcov-segfault-death</guid>
		<description><![CDATA[I was pounding my head against the keyboard. Rspec with rcov was crashing whenever it felt like it. I was getting all kinds of errors like: /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/matchers/be.rb:92: [BUG] rb_gc_mark(): unknown data type 0×0(0×489ffc8) non object ruby 1.8.6 (2007-09-24) [i686-darwin9.3.0] opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/example/example_group_methods.rb:344: [BUG] Segmentation fault ruby 1.8.6 (2007-09-24) [i686-darwin9.3.0] not to mention a bus error or two [...]]]></description>
			<content:encoded><![CDATA[<p>I was pounding my head against the keyboard.  Rspec with rcov was crashing whenever it felt like it.  I was getting all kinds of errors like:</p>
<pre class="brush: bash">/opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/matchers/be.rb:92: [BUG] rb_gc_mark(): unknown data type 0×0(0×489ffc8) non object
ruby 1.8.6 (2007-09-24) [i686-darwin9.3.0]

opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/example/example_group_methods.rb:344: [BUG] Segmentation fault
ruby 1.8.6 (2007-09-24) [i686-darwin9.3.0]</pre>
<p>not to mention a bus error or two as well.</p>
<p>Then I found <a href="http://mergulhao.info/2008/8/29/rcov-with-segfault-bug-patched">this article</a> with this solution:</p>
<pre class="brush: bash">$ gem sources -a http://gems.github.com (you only have to do this once)
$ sudo gem install mergulhao-rcov</pre>
<p>from <a href="http://tomcopeland.blogs.com/juniordeveloper/2008/08/rcov-crashing-w.html">this guy</a>.</p>
<p>Then the world was right again.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.elevationblog.com/2008/11/14/rspec-rcov-segfault-death/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Record Race Conditions</title>
		<link>http://dev.elevationblog.com/2008/08/07/active-record-race-conditions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=active-record-race-conditions</link>
		<comments>http://dev.elevationblog.com/2008/08/07/active-record-race-conditions/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 20:58:00 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[activerecord]]></category>

		<guid isPermaLink="false">http://elevationblog.com/2008/10/15/active-record-race-conditions</guid>
		<description><![CDATA[Today, I got bit by ActiveRecord race condition related to validates_uniqueness_of. Sometimes I just blindly trust that Rails is going to take care of things, and so it surprised me when I ended up with duplicate records in my database. A few people have written about this, and apparently it&#8217;s in the API Docs now, [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I got bit by ActiveRecord race condition related to validates_uniqueness_of.  Sometimes I just blindly trust that Rails is going to take care of things, and so it surprised me when I ended up with duplicate records in my database.  A <a href="http://drawohara.com/post/18926188/rails-activerecord-validations-are-fatally-flawed#disqus_thread">few</a> <a href="http://railswarts.blogspot.com/2007/11/validatesuniquenessof-is-broken-and.html">people</a> have written about this, and apparently it&#8217;s in the <a href="http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001330"><span class="caps">API</span> Docs</a> now, but I just hadn&#8217;t thought about it before.</p>
<p>The solution looks to be enforcing unique constraints at the database level.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.elevationblog.com/2008/08/07/active-record-race-conditions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Timestamps in join table causing readonly records</title>
		<link>http://dev.elevationblog.com/2008/07/31/timestamps-in-join-table-causing-readonly-recordds/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=timestamps-in-join-table-causing-readonly-recordds</link>
		<comments>http://dev.elevationblog.com/2008/07/31/timestamps-in-join-table-causing-readonly-recordds/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 18:40:00 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://elevationblog.com/2008/10/15/timestamps-in-join-table-causing-readonly-recordds</guid>
		<description><![CDATA[By default I include the rails t.timestamps in my create table migrations. Always nice to know when a model has been created or updated, right? And what could it hurt? Well, when they are in a join table for a habtm relationship they cause the associated records to be marked as readonly. This is because [...]]]></description>
			<content:encoded><![CDATA[<p>By default I include the rails t.timestamps in my create table migrations. Always nice to know when a model has been created or updated, right? And what could it hurt?</p>
<p>Well, when they are in a join table for a habtm relationship they cause the associated records to be marked as readonly. This is because rails can&#8217;t save those extra timestamp attributes.</p>
<p>If timestamps or any other extra join information is needed, then use a join model instead with has_many :through.</p>
<p><a href="http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M000981">more info</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.elevationblog.com/2008/07/31/timestamps-in-join-table-causing-readonly-recordds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>exception_notifier gotcha</title>
		<link>http://dev.elevationblog.com/2008/07/22/exception_notifier-gotcha/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=exception_notifier-gotcha</link>
		<comments>http://dev.elevationblog.com/2008/07/22/exception_notifier-gotcha/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 18:10:00 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[exception_notifier]]></category>

		<guid isPermaLink="false">http://elevationblog.com/2008/10/15/exception_notifier-gotcha</guid>
		<description><![CDATA[Yesterday I was investigating why exception_notifier wasn&#8217;t, well, notifying me of exceptions. I checked out the log, and I was getting an error like this: ActionView::TemplateError (protected method `filter_parameters' called for #&#60;Admin::ProductsController:0x2aaaaeccd6b0&#62;) Turns out Rails 2.1 breaks the version of exception notifier you get by running script/plugin install exception_notifier. To get the correct version, you [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I was investigating why exception_notifier wasn&#8217;t, well, notifying me of exceptions.</p>
<p>I checked out the log, and I was getting an error like this:</p>
<pre class="brush: bash">ActionView::TemplateError (protected method `filter_parameters' called for #&lt;Admin::ProductsController:0x2aaaaeccd6b0&gt;)</pre>
<p>Turns out Rails 2.1 breaks the version of exception notifier you get by running script/plugin install exception_notifier.  To get the correct version, you have to run script/plugin install git://github.com/rails/exception_notification.git</p>
<p>Pretty lame, they really should update that.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.elevationblog.com/2008/07/22/exception_notifier-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>form_builder tip</title>
		<link>http://dev.elevationblog.com/2008/06/16/form_builder-tip/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=form_builder-tip</link>
		<comments>http://dev.elevationblog.com/2008/06/16/form_builder-tip/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 19:00:00 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://elevationblog.com/2008/10/15/form_builder-tip</guid>
		<description><![CDATA[I ran into a situation this week where I had a single partial containing form fields being rendered for different models. Inside that partial, one of the fields was a text_field_with_autocomplete, which presented a problem, since form_builder doesn&#8217;t know anything about text_field_with auto_complete, and the text field certainly needed to know what model we were [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a situation this week where I had a single partial containing form fields being rendered for different models.  Inside that partial, one of the fields was a text_field_with_autocomplete, which presented a problem, since form_builder doesn&#8217;t know anything about text_field_with auto_complete, and the text field certainly needed to know what model we were working with here.  After a little digging, turns out form_builder exposes a getter called object_name:</p>
<pre class="brush: ruby">
&lt;%= text_field_with_auto_complete f.object_name, :city_name, ... %&gt;
</pre>
<p>Easy.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.elevationblog.com/2008/06/16/form_builder-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

