<?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>Think In Geek &#187; ruby on rails</title>
	<atom:link href="http://thinkingeek.com/tag/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://thinkingeek.com</link>
	<description>In geek we trust</description>
	<lastBuildDate>Wed, 01 Feb 2012 14:45:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Give your Ruby console a dash of colour</title>
		<link>http://thinkingeek.com/2012/02/01/give-ruby-console-dash-colour/</link>
		<comments>http://thinkingeek.com/2012/02/01/give-ruby-console-dash-colour/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 14:45:59 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[irb]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[wirble]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=232</guid>
		<description><![CDATA[When you&#8217;re developing an application in Rails (or Ruby), you spend lots of time in the IRB, the Interactive Ruby Shell. Usually just to test some Ruby code, start an application console or debug something going on inside the project. Yesterday, looking at a coworker screen, I saw he had his console with lots of [...]]]></description>
			<content:encoded><![CDATA[<p>
When you&#8217;re developing an application in Rails (or Ruby), you spend lots of time in the <em>IRB</em>, the Interactive Ruby Shell. Usually just to test some Ruby code, start an application console or debug something going on inside the project. Yesterday, looking at a coworker screen, I saw he had his console with lots of color hints, and I thought it was pretty nice. I asked him about that and he told me he was using a special gem for that.
</p>
<p>
The gem is called <a href="http://pablotron.org/software/wirble/" onclick="pageTracker._trackPageview('/outgoing/pablotron.org/software/wirble/?referer=');">wirble</a>. It has some nice defaults and allows you to configure the colors as you wish. To use it in your consoles, just add this lines to your <code>~/.irbrc</code> file:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">begin</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'wirble'</span>
  Wirble.<span style="color:#9900CC;">init</span>
  Wirble.<span style="color:#9900CC;">colorize</span>
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">LoadError</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> err
  warn <span style="color:#996600;">&quot;Couldn't load Wirble: #{err}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

</p>
<p>
Of course, you&#8217;ll need to install the gem. Just issue a <code>gem install wirble</code> and you&#8217;ll be good to go!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2012%2F02%2F01%2Fgive-ruby-console-dash-colour%2F&amp;title=Give%20your%20Ruby%20console%20a%20dash%20of%20colour" id="wpa2a_2" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2012_2F02_2F01_2Fgive-ruby-console-dash-colour_2F_amp_title=Give_20your_20Ruby_20console_20a_20dash_20of_20colour?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2012/02/01/give-ruby-console-dash-colour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix Java GUI applications in xmonad</title>
		<link>http://thinkingeek.com/2012/01/24/fix-java-gui-applications-xmonad/</link>
		<comments>http://thinkingeek.com/2012/01/24/fix-java-gui-applications-xmonad/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 15:00:12 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[rubymine]]></category>
		<category><![CDATA[xmonad]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=228</guid>
		<description><![CDATA[If you ever try to run a GUI Java application when using xmonad as the Window Manager, you&#8217;ll probably end up with a nice flat grey window where your buttons, toolbars and other desktop GUI goodies should be. I ran into that problem the other day when trying to evaluate the RubyMine Ruby on Rails [...]]]></description>
			<content:encoded><![CDATA[<p>
If you ever try to run a GUI Java application when using <a href="http://www.xmonad.org" onclick="pageTracker._trackPageview('/outgoing/www.xmonad.org?referer=');">xmonad</a> as the Window Manager, you&#8217;ll probably end up with a nice flat grey window where your buttons, toolbars and other desktop GUI goodies should be. I ran into that problem the other day when trying to evaluate the <a href="http://www.jetbrains.com/ruby/" onclick="pageTracker._trackPageview('/outgoing/www.jetbrains.com/ruby/?referer=');">RubyMine Ruby on Rails IDE</a> from which I heard such good things. After a rather painful installation of the official Java 6 JDK from Oracle in Ubuntu Lucid Lynx (which I&#8217;ll write about in some other time), I managed to start up RubyMine just to find out I was seeing absolutely nothing on the screen.
</p>
<p>
I Googled a bit and essentially I found out that the problem was with the Java GUI Toolkit rather than RubyMine, because <a href="http://www.haskell.org/haskellwiki/Xmonad/Frequently_asked_questions#Problems_with_Java_applications.2C_Applet_java_console" onclick="pageTracker._trackPageview('/outgoing/www.haskell.org/haskellwiki/Xmonad/Frequently_asked_questions_Problems_with_Java_applications.2C_Applet_java_console?referer=');">the framework relies on a list of window managers to handle some things, and xmonad is not in that list</a>.
</p>
<p>
So since I was not using OpenJDK, I opted for the <code>setWMName</code> option and added this final line into my <code>xmonad.hs</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">    xmonad <span style="color: #339933; font-weight: bold;">$</span> defaultConfig
      <span style="color: green;">&#123;</span> terminal            <span style="color: #339933; font-weight: bold;">=</span> myTerminal
      <span style="color: #339933; font-weight: bold;">,</span> workspaces          <span style="color: #339933; font-weight: bold;">=</span> myWorkspaces
      <span style="color: #339933; font-weight: bold;">,</span> keys                <span style="color: #339933; font-weight: bold;">=</span> keys'
      <span style="color: #339933; font-weight: bold;">,</span> modMask             <span style="color: #339933; font-weight: bold;">=</span> modMask'
      <span style="color: #339933; font-weight: bold;">,</span> layoutHook          <span style="color: #339933; font-weight: bold;">=</span> layoutHook'
      <span style="color: #339933; font-weight: bold;">,</span> manageHook          <span style="color: #339933; font-weight: bold;">=</span> manageHook'
      <span style="color: #339933; font-weight: bold;">,</span> logHook             <span style="color: #339933; font-weight: bold;">=</span> myLogHook dzenLeftBar <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> fadeInactiveLogHook 0xdddddddd
      <span style="color: #339933; font-weight: bold;">,</span> normalBorderColor   <span style="color: #339933; font-weight: bold;">=</span> colorNormalBorder
      <span style="color: #339933; font-weight: bold;">,</span> focusedBorderColor  <span style="color: #339933; font-weight: bold;">=</span> colorFocusedBorder
      <span style="color: #339933; font-weight: bold;">,</span> borderWidth         <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">2</span>
      <span style="color: #339933; font-weight: bold;">,</span> startupHook         <span style="color: #339933; font-weight: bold;">=</span> setWMName <span style="background-color: #3cb371;">&quot;LG3D&quot;</span>
<span style="color: green;">&#125;</span></pre></div></div>

</p>
<p>
Setting the window manager name to <em>LG3D</em> will trick the Java GUI Toolkit and the application will be painted correctly.
</p>
<p>
Enjoy your Java applications with the power of xmonad!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2012%2F01%2F24%2Ffix-java-gui-applications-xmonad%2F&amp;title=Fix%20Java%20GUI%20applications%20in%20xmonad" id="wpa2a_4" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2012_2F01_2F24_2Ffix-java-gui-applications-xmonad_2F_amp_title=Fix_20Java_20GUI_20applications_20in_20xmonad?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2012/01/24/fix-java-gui-applications-xmonad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails Many To Many associations with multiple databases</title>
		<link>http://thinkingeek.com/2012/01/24/ruby-rails-associations-multiple-databases/</link>
		<comments>http://thinkingeek.com/2012/01/24/ruby-rails-associations-multiple-databases/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 12:54:53 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=220</guid>
		<description><![CDATA[Sometimes you need to use multiple databases in your Rails projects. Usually when some data must be shared between different applications. When this happens you usually have some models in a shared database, and some other models in the specific application database. This can be easily done using the establish_connection method in the shared models [...]]]></description>
			<content:encoded><![CDATA[<p>
Sometimes you need to use multiple databases in your Rails projects. Usually when some data must be shared between different applications. When this happens you usually have some models in a shared database, and some other models in the specific application database. This can be easily done using the <a href="http://apidock.com/rails/ActiveRecord/Base/establish_connection/class" onclick="pageTracker._trackPageview('/outgoing/apidock.com/rails/ActiveRecord/Base/establish_connection/class?referer=');">establish_connection</a> method in the shared models to tell them they have to connect to a different database.
</p>
<p>
However, when you need some interaction between those <em>shared models</em> and the models of your specific application, like a <a href="http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many" onclick="pageTracker._trackPageview('/outgoing/apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many?referer=');">has_many, :through</a> association, some problems arise. The typical <em>Many To Many</em> association uses an intermediate database table that links the relation between two models, and allows you to add some extra information on that relation. When navigating through the association, Rails tries to make an SQL query that joins the model with this intermediate table. For example, imagine you have a <em>Team</em> model, which has many <em>Players</em>, but a player can also be on more than one team. We use an intermediate model <em>TeamPlayers</em> (and we can also use it to save the role of that player into that team, for example). You would have those three tables:</p>
<ul>
<li>teams</li>
<li>players</li>
<li>teams_players</li>
</ul>
<p>When asking for the players of a given Team, Rails would do something similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">&quot;players&quot;</span><span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">&quot;players&quot;</span> <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> teams_players<span style="color: #ff0000;">&quot; ON &quot;</span>players<span style="color: #ff0000;">&quot;.id = &quot;</span>teams_players<span style="color: #ff0000;">&quot;.player_id WHERE &quot;</span>players<span style="color: #ff0000;">&quot;.team_id = 1</span></pre></div></div>

<p>Where <code>1</code> is the <em>id</em> of the team you asked for. This [obviously] works perfectly fine when everything is in the same database, and it&#8217;s as efficient as the SQL database manager you&#8217;re using. What happens, however, when we have the Player model in another database? It will miserably fail because Rails will try to join with a  table that doesn&#8217;t exist.
</p>
<p>
Unfortunately, there&#8217;s no efficient way to solve this problem, that is, using SQL, as you can&#8217;t work with tables from different databases. However, there&#8217;s a rather elegant solution that <a href="http://emphaticsolutions.com/2009/11/23/has_many_through_across_databases.html" onclick="pageTracker._trackPageview('/outgoing/emphaticsolutions.com/2009/11/23/has_many_through_across_databases.html?referer=');">Brian Doll</a> cared to implement as a <a href="https://github.com/briandoll/st-elsewhere" onclick="pageTracker._trackPageview('/outgoing/github.com/briandoll/st-elsewhere?referer=');">gem</a> a while ago. As indicated in the GitHub readme, you just have to use a <code>has_many_elsewhere</code> relation instead of the usual one, and make sure that the model referenced has the connection established to the shared database. And that&#8217;s all.
</p>
<p>
The <em>magic</em> donde behind the scenes is pretty simple: this gem just replicates the same methods that the <code>ActiveRecord::Base</code> class does in the <em>has_many</em> method call, changing the failing unique SQL calls to double SQL calls, one for each database, fetching the intermediate models first, and then fetching the remote models using those ids.
</p>
<p>
This method is not perfect, as probably not all the goodness of the original association can be done with it, but for simple scenarios is more than enough.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2012%2F01%2F24%2Fruby-rails-associations-multiple-databases%2F&amp;title=Ruby%20on%20Rails%20Many%20To%20Many%20associations%20with%20multiple%20databases" id="wpa2a_6" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2012_2F01_2F24_2Fruby-rails-associations-multiple-databases_2F_amp_title=Ruby_20on_20Rails_20Many_20To_20Many_20associations_20with_20multiple_20databases?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2012/01/24/ruby-rails-associations-multiple-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating your own Job Managers in Ubiquo</title>
		<link>http://thinkingeek.com/2011/12/02/creating-job-managers-ubiquo/</link>
		<comments>http://thinkingeek.com/2011/12/02/creating-job-managers-ubiquo/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 11:00:02 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[ubiquo]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=203</guid>
		<description><![CDATA[Ubiquo is a Ruby on Rails, MIT Licensed Open Source CMS we develop and use at gnuine for a variety of projects. One of the features of Ubiquo is the ability to run jobs separately from the http requests to the site. Today I&#8217;m going to show you how to customize the Ubiquo Jobs plugin [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ubiquo.me" onclick="pageTracker._trackPageview('/outgoing/www.ubiquo.me?referer=');">Ubiquo</a> is a <a href="http://rubyonrails.org/" onclick="pageTracker._trackPageview('/outgoing/rubyonrails.org/?referer=');">Ruby on Rails</a>, <a href="http://www.opensource.org/licenses/mit-license.php" onclick="pageTracker._trackPageview('/outgoing/www.opensource.org/licenses/mit-license.php?referer=');">MIT Licensed</a> Open Source <a href="http://en.wikipedia.org/wiki/Content_management_system" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Content_management_system?referer=');">CMS</a> we develop and use at <a href="http://www.gnuine.com" onclick="pageTracker._trackPageview('/outgoing/www.gnuine.com?referer=');">gnuine</a> for a variety of projects. One of the features of Ubiquo is the ability to run jobs separately from the http requests to the site. Today I&#8217;m going to show you how to customize the Ubiquo Jobs plugin to create your own types of jobs and managers to launch them.</p>
<p>Sometimes can be useful to create different managers. An example of this situation is when you want to run different kind of jobs in different circumstances.</p>
<p>Ubiquo Jobs provides a default manager which will get <tt>ActiveJob</tt> jobs depending on priorities and schedule times:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span>runner<span style="color:#006600; font-weight:bold;">&#41;</span>
  recovery<span style="color:#006600; font-weight:bold;">&#40;</span>runner<span style="color:#006600; font-weight:bold;">&#41;</span>
  candidate_jobs = job_class.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span>
    <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>
      <span style="color:#996600;">'planified_at &lt;= ? AND state = ?'</span>,
      <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">utc</span>,
      <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::Base::STATES</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:waiting</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#006600; font-weight:bold;">&#93;</span>,
    <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'priority asc'</span>
  <span style="color:#006600; font-weight:bold;">&#41;</span>
  job = first_without_dependencies<span style="color:#006600; font-weight:bold;">&#40;</span>candidate_jobs<span style="color:#006600; font-weight:bold;">&#41;</span>
  job.<span style="color:#9900CC;">update_attributes</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:state</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::Base::STATES</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:instantiated</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
      <span style="color:#ff3333; font-weight:bold;">:runner</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> runner
    <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> job
  job
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The <tt>job_class</tt> variable defaults to <tt>UbiquoJobs::Jobs::ActiveJob</tt>. If you want to make your own manager to handle special jobs, or change the way the jobs are picked, the best way to do so is to implement your own manager. A nice rails-like way to do that is include them in the <tt>lib/</tt> folder of your ubiquo project.<br />
The class you should inherit from is <tt>UbiquoJobs::Managers::ActiveManager</tt>. If you wanted the manager to just pick up a specific subclass of ubiquo jobs, it would suffice to reimplement the <tt>self.job_class</tt> class method to return your own kind of job:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">job_class</span>
  <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::YourJobClass</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>However, there&#8217;s a better way to do this. For this special case, the default <tt>UbiquoJob</tt> class provides a special member which stores the job&#8217;s class name, allowing you to select all objects subclasses of <tt>ActiveJob</tt> by its classname. For example, imagine you have a kind of job for special tasks that you know for sure will take a long time to complete. Seems reasonable to have a different manager to handle those jobs. You would create a new job in the file <tt>app/jobs/very_long_job.rb</tt>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> VeryLongJob <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::ActiveJob</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> do_job_work
    <span style="color:#008000; font-style:italic;">#Do what needs to be done here</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006666;">0</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Then you could create a manager that handles only those kind of jobs by implementing your own subclass of the <tt>UbiquoJobs::Managers::ActiveManager</tt> class:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> JobManagers
  <span style="color:#9966CC; font-weight:bold;">class</span> VeryLongJobManager <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Managers::ActiveManager</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span>runner<span style="color:#006600; font-weight:bold;">&#41;</span>
      recovery<span style="color:#006600; font-weight:bold;">&#40;</span>runner<span style="color:#006600; font-weight:bold;">&#41;</span>
      candidate_jobs = job_class.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span>
        <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>
          <span style="color:#996600;">'planified_at &lt;= ? AND state = ? AND type = ?'</span>, 
          <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">utc</span>,
          <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::Base::STATES</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:waiting</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
          <span style="color:#996600;">'VeryLongJob'</span>
        <span style="color:#006600; font-weight:bold;">&#93;</span>,
        <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'priority asc'</span>
      <span style="color:#006600; font-weight:bold;">&#41;</span>
      job = first_without_dependencies<span style="color:#006600; font-weight:bold;">&#40;</span>candidate_jobs<span style="color:#006600; font-weight:bold;">&#41;</span>
      job.<span style="color:#9900CC;">update_attributes</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>
          <span style="color:#ff3333; font-weight:bold;">:state</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::Base::STATES</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:instantiated</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
          <span style="color:#ff3333; font-weight:bold;">:runner</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> runner
        <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> job
      job
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The code is exactly the same as the default <tt>ActiveManager</tt> class, but the finder will take an extra parameter, <tt>'VeryLongJob'</tt>, to indicate that only the <tt>ActiveJob</tt> objects that are of the subclass <tt>VerylongJob</tt> should be taken.</p>
<p>After that, you need to modify the task that calls the workers so it takes your manager, or create a new task that will run your manager. The default task that will<br />
start a worker looks as this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">desc <span style="color:#996600;">&quot;Starts a new ubiquo worker&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:start</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:interval</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:environment</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t, args<span style="color:#006600; font-weight:bold;">|</span>
  options = <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:sleep_time</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> args.<span style="color:#9900CC;">interval</span>.<span style="color:#9900CC;">to_f</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">delete_if</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>k,v<span style="color:#006600; font-weight:bold;">|</span> v.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">&#125;</span>
  UbiquoWorker.<span style="color:#9900CC;">init</span><span style="color:#006600; font-weight:bold;">&#40;</span>args.<span style="color:#9900CC;">name</span>, options<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This uses a special configuration parameter to determine the manager to use. This configuration option is stored in <tt>Ubiquo::Config.context(:ubiquo_jobs)</tt>, the name of the configuration option is <tt>:job_manager_class</tt>, and takes the manager class as a value. So in order to create a task that will use your manager, you should create a new task like this one:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">desc <span style="color:#996600;">&quot;Starts a new ubiquo worker&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:start_very_long_jobs</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:interval</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:environment</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t, args<span style="color:#006600; font-weight:bold;">|</span>
  options = <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:sleep_time</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> args.<span style="color:#9900CC;">interval</span>.<span style="color:#9900CC;">to_f</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">delete_if</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>k,v<span style="color:#006600; font-weight:bold;">|</span> v.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#6666ff; font-weight:bold;">Ubiquo::Config</span>.<span style="color:#9900CC;">context</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:ubiquo_jobs</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:job_manager_class</span>, <span style="color:#6666ff; font-weight:bold;">JobManagers::VeryLongJobManager</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  UbiquoWorker.<span style="color:#9900CC;">init</span><span style="color:#006600; font-weight:bold;">&#40;</span>args.<span style="color:#9900CC;">name</span>, options<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Your should call this task like this (assuming it&#8217;s on the same namespace as the default task):</p>
<p><code><br />
rake ubiquo:worker:start_very_long_jobs[name,interval]<br />
</code></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F12%2F02%2Fcreating-job-managers-ubiquo%2F&amp;title=Creating%20your%20own%20Job%20Managers%20in%20Ubiquo" id="wpa2a_8" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F12_2F02_2Fcreating-job-managers-ubiquo_2F_amp_title=Creating_20your_20own_20Job_20Managers_20in_20Ubiquo?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/12/02/creating-job-managers-ubiquo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iterate over a collection in groups, and other things</title>
		<link>http://thinkingeek.com/2011/10/20/iterate-collection-groups/</link>
		<comments>http://thinkingeek.com/2011/10/20/iterate-collection-groups/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 15:44:51 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[enumerable]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=188</guid>
		<description><![CDATA[One thing I find fascinating about Ruby is the fact that most common tasks are already programmed for you in its library. The Enumerable module is a clear example of that, providing you with lots of functionality to manipulate collections of objects. One of those useful methods I discovered the other day was each_slice. This [...]]]></description>
			<content:encoded><![CDATA[<p>
One thing I find fascinating about Ruby is the fact that most common tasks are already programmed for you in its library. The <em>Enumerable</em> module is a clear example of that, providing you with lots of functionality to manipulate collections of objects.
</p>
<p>
One of those useful methods I discovered the other day was <em><a href="http://www.ruby-doc.org/core-1.9.2/Enumerable.html#method-i-each_slice" onclick="pageTracker._trackPageview('/outgoing/www.ruby-doc.org/core-1.9.2/Enumerable.html_method-i-each_slice?referer=');">each_slice</a></em>. This method allows you to iterate over the collection, just as <em>each</em> does, but lets you do it changing how many elements of the collection you get on each iteration. This is the example you can get from the documentation page:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>..<span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each_slice</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>a<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">p</span> a<span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># outputs below</span>
<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">4</span>, <span style="color:#006666;">5</span>, <span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">7</span>, <span style="color:#006666;">8</span>, <span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

</p>
<p>
You can see that from the original array from 1 to 10, on every iteration Ruby prints the numbers in groups of three, and the last one alone since the collection is not a multiple of 3. Now think about having to do this manually: it&#8217;s not that hard, but its error prone and you have to do all that typical arithmetic logic that should be easy but never is. How handy that Ruby has already done that job for you.
</p>
<p>
This method is also pretty useful when working in <em>Ruby on Rails</em>. One simple example is when you have to manually implement some kind of pagination, or show a list of elements in columns or rows of fixed size: you have to simply iterate with <em>each_slice</em> and put the page/row/column logic on the block, and <em>voilà</em>.
</p>
<p>
I strongly suggest you take a look at the <a href="http://www.ruby-doc.org/core-1.9.2/Enumerable.html" onclick="pageTracker._trackPageview('/outgoing/www.ruby-doc.org/core-1.9.2/Enumerable.html?referer=');">Enumerable</a> module reference to take a look at all the other flavours of <em>each</em> methods it has and I&#8217;m sure you&#8217;ll find all of them pretty useful in lots of situations!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F10%2F20%2Fiterate-collection-groups%2F&amp;title=Iterate%20over%20a%20collection%20in%20groups%2C%20and%20other%20things" id="wpa2a_10" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F10_2F20_2Fiterate-collection-groups_2F_amp_title=Iterate_20over_20a_20collection_20in_20groups_2C_20and_20other_20things?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/10/20/iterate-collection-groups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easily select random records in rails</title>
		<link>http://thinkingeek.com/2011/07/04/easily-select-random-records-rails/</link>
		<comments>http://thinkingeek.com/2011/07/04/easily-select-random-records-rails/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 18:26:50 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=184</guid>
		<description><![CDATA[If you ever wondered how to easily retrieve a random record in an ActiveRecord model, here&#8217;s en easy way to do that: use the sample method. sample is a class method from the Array class that retrieves one or more random items from an array instance. It conveniently returns nil or an array lesser than [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever wondered how to easily retrieve a random record in an <em>ActiveRecord</em> model, here&#8217;s en easy way to do that: use the <a href="http://www.ruby-doc.org/core/classes/Array.html#M000285" onclick="pageTracker._trackPageview('/outgoing/www.ruby-doc.org/core/classes/Array.html_M000285?referer=');">sample</a> method.</p>
<p><em>sample</em> is a class method from the <em>Array</em> class that retrieves one or more random items from an array instance. It conveniently returns <em>nil</em> or an array lesser than the items requested if the original array has not enough items.</p>
<p>Since all <em>ActiveRecord</em> <em>find</em>s return an array, you can easily add the sample call at the end of a <em>find</em> call to get the random items you need from complex queries.</p>
<p>For example, imagine you have a Book model which has a published_at datetime attribute and you want to show, in your library home page, a random selection of 5 books that have been published. You can easily get those using this snippet:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> get_random_books_for_home_page
  find<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">sample</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F07%2F04%2Feasily-select-random-records-rails%2F&amp;title=Easily%20select%20random%20records%20in%20rails" id="wpa2a_12" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F07_2F04_2Feasily-select-random-records-rails_2F_amp_title=Easily_20select_20random_20records_20in_20rails?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/07/04/easily-select-random-records-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fixtures and serialized attributes in Ruby on Rails</title>
		<link>http://thinkingeek.com/2011/06/16/fixtures-and-serialized-attributes-in-ruby-on-rails/</link>
		<comments>http://thinkingeek.com/2011/06/16/fixtures-and-serialized-attributes-in-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 17:46:59 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[serialize]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=175</guid>
		<description><![CDATA[If you&#8217;ve ever used the serialize method in an ActiveRecord model, you may have faced the problem of writing a fixture for that particular serialized field. The serialize method is quite handy if you need to store a complex object (like a Hash or an Array) in a database field, without having to create additional [...]]]></description>
			<content:encoded><![CDATA[<p>
If you&#8217;ve ever used the <a href="http://apidock.com/rails/ActiveRecord/Base/serialize/class" onclick="pageTracker._trackPageview('/outgoing/apidock.com/rails/ActiveRecord/Base/serialize/class?referer=');">serialize</a> method in an ActiveRecord model, you may have faced the problem of writing a fixture for that particular serialized field. The serialize method is quite handy if you need to store a complex object (like a Hash or an Array) in a database field, without having to create additional models and relationships between them. A good example could be store the preferences of a user in a hash:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
    serialize <span style="color:#ff3333; font-weight:bold;">:preferences</span>, <span style="color:#CC00FF; font-weight:bold;">Hash</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

</p>
<p>
This way you can set and get the <em>preferences</em> attribute of the user without having to worry much about it:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">User.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">preferences</span> <span style="color:#008000; font-style:italic;"># =&gt; {:show_email =&gt; true, :allow_pm =&gt; :false, ...}</span>
user = User.<span style="color:#9900CC;">first</span>
user.<span style="color:#9900CC;">preferences</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>:show_email <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:allow_pm</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> :<span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#125;</span>
user.<span style="color:#9900CC;">save</span></pre></div></div>

</p>
<p>
In order to do that, at the database table for the <em>User</em> class, among the other fields you&#8217;ll need to add a <em>text</em> column for the preferences. After that, you can easily work with your model without too much of a hassle.
</p>
<p>
If you care to look at the rows of the model&#8217;s table, you&#8217;ll see that the serialized attribute is stored in <a href="http://www.yaml.org/" onclick="pageTracker._trackPageview('/outgoing/www.yaml.org/?referer=');">YAML</a> format:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sqlite&gt; select preferences from users where id = 1;
--- 
:show_email: false
:allow_pm: false</pre></div></div>

</p>
<p>
Now, that if you need to add a <a href="http://rails.rubyonrails.org/classes/Fixtures.html" onclick="pageTracker._trackPageview('/outgoing/rails.rubyonrails.org/classes/Fixtures.html?referer=');">fixture</a> for your model that needs the <em>preferences</em> attribute to be set to a particular value? If you have to manually parse the value you want to put in there to be tested, it&#8217;ll be a pain in the ass. Even if you have a script that converts certain values to YAML so you can copy and paste the script output to the fixture, it&#8217;s not very comfortable. Hopefully, you have to remember that you can use some <a href="http://ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html" onclick="pageTracker._trackPageview('/outgoing/ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html?referer=');">ERB</a> magic in your fixtures <img src='http://thinkingeek.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  So, here&#8217;s the deal if you need to add something to the serializable attribute:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">one:
  preferences: &lt;%= {:show_email =&gt; true, :allow_pm =&gt; :false}.to_yaml.inspect  %&gt;</pre></div></div>

</p>
<p>
The <em>to_yaml</em> method converts the Hash into a YAML representation, and with <em>inspect</em> we convert that to a string. Using this technique, we can add whatever we want to a serialized field in our fixtures.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F06%2F16%2Ffixtures-and-serialized-attributes-in-ruby-on-rails%2F&amp;title=Fixtures%20and%20serialized%20attributes%20in%20Ruby%20on%20Rails" id="wpa2a_14" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F06_2F16_2Ffixtures-and-serialized-attributes-in-ruby-on-rails_2F_amp_title=Fixtures_20and_20serialized_20attributes_20in_20Ruby_20on_20Rails?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/06/16/fixtures-and-serialized-attributes-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create your own JSONP Proxy using Ruby on Rails</title>
		<link>http://thinkingeek.com/2011/03/09/create-your-own-jsonp-proxy-using-ruby-on-rails/</link>
		<comments>http://thinkingeek.com/2011/03/09/create-your-own-jsonp-proxy-using-ruby-on-rails/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 13:01:12 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jsonp]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=157</guid>
		<description><![CDATA[Today I was working on a web site that needs to retrieve some RSS feed over the internet. Since the web page has no server (HTML + javascript only) I couldn&#8217;t access the feed from the server side. Also, because of the Cross Domain limitation of Ajax requests, I couldn&#8217;t access the RSS in the [...]]]></description>
			<content:encoded><![CDATA[<p>
Today I was working on a web site that needs to retrieve some RSS feed over the internet. Since the web page has no server (HTML + javascript only) I couldn&#8217;t access the feed from the server side. Also, because of the Cross Domain limitation of Ajax requests, I couldn&#8217;t access the RSS in the client either. I searched Google for an API and found the <a href="http://code.google.com/apis/feed/" onclick="pageTracker._trackPageview('/outgoing/code.google.com/apis/feed/?referer=');">Google Feed API</a>, which does exactly what I want. However, because (I think) Google caches the RSS feed you request, there was a significant delay (about half an hour) between the update of the RSS contents and the RSS provided by Google (the feed was updated in a per minute basis, as it was a CoverItLive event). Seeing I couldn&#8217;t access really recent posts from the feed using Google, I decided to implement my own RSS API using JSONP in a ruby on rails environment, since having an external server act as a proxy was allowed for the overall solution.
</p>
<p>
The tools I needed I got from those two websites: <a href="http://rubyrss.com/" onclick="pageTracker._trackPageview('/outgoing/rubyrss.com/?referer=');">http://rubyrss.com/</a> for a RSS parser, and <a href="http://blogs.sitepoint.com/2006/10/05/json-p-output-with-rails/" onclick="pageTracker._trackPageview('/outgoing/blogs.sitepoint.com/2006/10/05/json-p-output-with-rails/?referer=');">http://blogs.sitepoint.com/2006/10/05/json-p-output-with-rails/</a> on how to build a simple JSONP response on the server side.
</p>
<p>
Basically you have to start creating a new controller that will handle the JSONP requests. In my case I just added a &#8216;Feed&#8217; controller:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ script<span style="color: #000000; font-weight: bold;">/</span>generate controller Feed</pre></div></div>

</p>
<p>
Then you edit the <em>app/controllers/feed_controller.rb</em> file and start coding. We will assume that the request will come in this form: <em>http://server/feed/get?callback=some_callback&#038;url=the_url_of_the_feed</em>. Having this information, the controller code is pretty straightforward.
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> FeedController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
&nbsp;
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rss/1.0'</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rss/2.0'</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> get
    <span style="color:#9966CC; font-weight:bold;">begin</span>
      url_contents = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">URI</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:url</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      rss = <span style="color:#6666ff; font-weight:bold;">RSS::Parser</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>url_contents, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      json = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;error&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#996600;">&quot;feed&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> rss <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">to_json</span>
    <span style="color:#9966CC; font-weight:bold;">rescue</span>
      json = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;error&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">to_json</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">js</span> <span style="color:#006600; font-weight:bold;">&#123;</span> render_json json <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> render_json<span style="color:#006600; font-weight:bold;">&#40;</span>json<span style="color:#006600; font-weight:bold;">&#41;</span>
    callback = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:callback</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    response = <span style="color:#9966CC; font-weight:bold;">begin</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> callback
        <span style="color:#996600;">&quot;#{callback}(#{json});&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        json
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    render<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>:content_type <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:js</span>, <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> response<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

</p>
<p>The first two lines are the requirements for the <em>RSS</em> module, which will allow us to parse a RSS feed. After that, we start with the <em>get</em> request. In there, we use the <em>Net::HTTP.get()</em> method, which will retrieve a URL content using a GET request and return its contents. To do so, we need to pass it an <em>uri</em> parameter, which we can get from the entire URL using the method <em>URI.parse()</em>. After this call, we have the XML of the RSS feed in <em>url_contents</em>. What we have to do now is build an RSS object with this XML. We&#8217;ll do that by calling <em>RSS::Parser.parse()</em>. If you wish to do some modifications to the RSS contents, now is your change. In this simple example we&#8217;ll simply bulk it all to the response.
</p>
<p>
To build the response, we need a JSON object. If everything went as expected, we can create a JSON object by simply creating a ruby associative array and calling the <em>to_json</em> method on it:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">json = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;error&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#996600;">&quot;feed&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> rss <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">to_json</span></pre></div></div>

</p>
<p>
If, on the contrary, we got an error (bad URL, bad RSS, whatever), we simply return the same JSON object with the <em>error</em> property set to true (that&#8217;s done in the <em>rescue</em> clause).
</p>
<p>
After we have this JSON object built, we simply have to output the results. To do so, we use the help of a method called <em>render_json</em> which we have added to the controller code. In this method we simply output the JSON if we provide no callback (this means no JSONP), or either a padded JSON (hence the name JSONP) with the callback name followed by the JSON data. In either case we render the results as a <em>js</em> type.
</p>
<p>
For more detailed information on how JSONP works, check <a href="http://en.wikipedia.org/wiki/JSON#JSONP" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/JSON_JSONP?referer=');">http://en.wikipedia.org/wiki/JSON#JSONP</a>, but what you basically need to know is that when you do a JSONP request what you&#8217;re really doing is retrieve a chunk of javascript code that will be run on your client, so be aware of the security issues you can have here.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F03%2F09%2Fcreate-your-own-jsonp-proxy-using-ruby-on-rails%2F&amp;title=Create%20your%20own%20JSONP%20Proxy%20using%20Ruby%20on%20Rails" id="wpa2a_16" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F03_2F09_2Fcreate-your-own-jsonp-proxy-using-ruby-on-rails_2F_amp_title=Create_20your_20own_20JSONP_20Proxy_20using_20Ruby_20on_20Rails?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/03/09/create-your-own-jsonp-proxy-using-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Killing all rails logs with one Ctrl+C?</title>
		<link>http://thinkingeek.com/2007/09/08/killing-all-rails-logs-with-one-ctrlc/</link>
		<comments>http://thinkingeek.com/2007/09/08/killing-all-rails-logs-with-one-ctrlc/#comments</comments>
		<pubDate>Sat, 08 Sep 2007 17:28:12 +0000</pubDate>
		<dc:creator>jsegura</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=76</guid>
		<description><![CDATA[Well, this is my first post after holidays and it won&#8217;t be very long. Imagine you are developing a rails application. Usually you have: a terminal with the server to see what petitions are received. a terminal with a tail of development.log to see what happens with the database. a terminal with a tail of [...]]]></description>
			<content:encoded><![CDATA[<p>Well, this is my first post after holidays and it won&#8217;t be very long.</p>
<p>Imagine you are developing a rails application. Usually you have:</p>
<ul>
<li>a terminal with the server to see what petitions are received.</li>
<li> a terminal with a tail of development.log to see what happens with the database.</li>
<li> a terminal with a tail of test.log if you are testing something.</li>
</ul>
<p>
This are a <strong>lot</strong> of windows&#8230; And the other day one friends was very happy and after asking for a while I discovered that the reason was the simple line showed above&#8230; With only one <strong>Ctrl+C</strong> you can kill all this processes <img src='http://thinkingeek.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">script<span style="color: #000000; font-weight: bold;">/</span>server <span style="color: #000000; font-weight: bold;">&amp;</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> log<span style="color: #000000; font-weight: bold;">/</span>development.log <span style="color: #000000; font-weight: bold;">&amp;</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> log<span style="color: #000000; font-weight: bold;">/</span>test.log <span style="color: #000000; font-weight: bold;">&amp;</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> ; <span style="color: #7a0874; font-weight: bold;">jobs</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print &quot;kill -2 &quot; $0}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sh</span></pre></div></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2007%2F09%2F08%2Fkilling-all-rails-logs-with-one-ctrlc%2F&amp;title=Killing%20all%20rails%20logs%20with%20one%20Ctrl%2BC%3F" id="wpa2a_18" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2007_2F09_2F08_2Fkilling-all-rails-logs-with-one-ctrlc_2F_amp_title=Killing_20all_20rails_20logs_20with_20one_20Ctrl_2BC_3F?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2007/09/08/killing-all-rails-logs-with-one-ctrlc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subversioning a Rails App</title>
		<link>http://thinkingeek.com/2007/06/22/subversioning-a-rails-app/</link>
		<comments>http://thinkingeek.com/2007/06/22/subversioning-a-rails-app/#comments</comments>
		<pubDate>Fri, 22 Jun 2007 14:02:02 +0000</pubDate>
		<dc:creator>jsegura</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=42</guid>
		<description><![CDATA[The time when application versions where stored in different folders or in zip files has ended. Today we have great tools like Subversion or CVS. This tools must be known by everybody, but for those who aren&#8217;t known, they are applications that control versions of files. While developing a Ruby on Rails application it&#8217;s good [...]]]></description>
			<content:encoded><![CDATA[<p>The time when application versions where stored in different folders or in zip files has ended. Today we have great tools like Subversion or CVS. This tools must be known by everybody, but for those who aren&#8217;t known, they are applications that control versions of files.</p>
<p>While developing a Ruby on Rails application it&#8217;s good to use a system like Subversion. In this howto I&#8217;ll explain my experience subversioning my Rails app.</p>
<p><span id="more-42"></span></p>
<p>The first step is to create a subversion repository. Mine is created with a web interface in my hosting account, if you can control your subversion repositories and you don&#8217;t know how to create it the chapter <a href="http://svnbook.red-bean.com/nightly/en/svn.reposadmin.create.html" onclick="pageTracker._trackPageview('/outgoing/svnbook.red-bean.com/nightly/en/svn.reposadmin.create.html?referer=');">Creating and Configuring your Repository</a> from SVN book may be useful. My repository url is (for example) http://someaccount.somehosting/myapp.</p>
<p>For subversioning a rails app we need, of course, a rails app. We&#8217;ll create a dummy app for testing. After that we have to import this directory structure to our repository</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails $ rails demo
      create 
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers
      create  app<span style="color: #000000; font-weight: bold;">/</span>models
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts
      create  config<span style="color: #000000; font-weight: bold;">/</span>environments
jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails$ <span style="color: #c20cb9; font-weight: bold;">svn</span> import demo http:<span style="color: #000000; font-weight: bold;">//</span>someaccount.somehosting<span style="color: #000000; font-weight: bold;">/</span>demo <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;Rails import&quot;</span></pre></div></div>

<p>The next actions have to be done in a working copy, the directory demo is no longer necessary.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails $ <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> demo
jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails $</pre></div></div>

<p>After obtaining the working copy we have to prepare our repository for developers usage. The steps are:</p>
<ol>
<li>Removing temp files</li>
<li>Removing log files</li>
</ol>
<p>To remove these files doesn&#8217;t mean &#8220;they are unnecessary&#8221;, only means &#8220;there is unnecessary for these files to stay in the repo&#8221; <img src='http://thinkingeek.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>demo$ <span style="color: #c20cb9; font-weight: bold;">svn</span> remove log<span style="color: #000000; font-weight: bold;">/&lt;</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span>
D         log<span style="color: #000000; font-weight: bold;">/</span>development.log
D         log<span style="color: #000000; font-weight: bold;">/</span>production.log
D         log<span style="color: #000000; font-weight: bold;">/</span>server.log
D         log<span style="color: #000000; font-weight: bold;">/</span>test.log
jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>demo$ <span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;*.log&quot;</span> log<span style="color: #000000; font-weight: bold;">/</span>
property <span style="color: #ff0000;">'svn:ignore'</span> <span style="color: #000000; font-weight: bold;">set</span> on <span style="color: #ff0000;">'log'</span>
jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>demo <span style="color: #c20cb9; font-weight: bold;">svn</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span>            <span style="color: #c20cb9; font-weight: bold;">svndumpfilter</span>  <span style="color: #c20cb9; font-weight: bold;">svnserve</span>       <span style="color: #c20cb9; font-weight: bold;">svnversion</span>     
<span style="color: #c20cb9; font-weight: bold;">svnadmin</span>       <span style="color: #c20cb9; font-weight: bold;">svnlook</span>        <span style="color: #c20cb9; font-weight: bold;">svnsync</span>       
jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>demo$ <span style="color: #c20cb9; font-weight: bold;">svn</span> ci <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;Remove and ignore log files&quot;</span>
Sending        demo<span style="color: #000000; font-weight: bold;">/</span>log
Deleting       demo<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>development.log
Deleting       demo<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>production.log
Deleting       demo<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>server.log
Deleting       demo<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>test.log
&nbsp;
Committed revision <span style="color: #000000;">3</span>.</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>demo$ <span style="color: #c20cb9; font-weight: bold;">svn</span> remove tmp<span style="color: #000000; font-weight: bold;">/&lt;/</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span>
D         tmp<span style="color: #000000; font-weight: bold;">/</span>cache
D         tmp<span style="color: #000000; font-weight: bold;">/</span>pids
D         tmp<span style="color: #000000; font-weight: bold;">/</span>sessions
D         tmp<span style="color: #000000; font-weight: bold;">/</span>sockets
jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>demo <span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;*&quot;</span> tmp<span style="color: #000000; font-weight: bold;">/</span>
property <span style="color: #ff0000;">'svn:ignore'</span> <span style="color: #000000; font-weight: bold;">set</span> on <span style="color: #ff0000;">'tmp'</span>
jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>demo$ <span style="color: #c20cb9; font-weight: bold;">svn</span> ci <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;Remove and ignore temp files&quot;</span>
Sending        demo<span style="color: #000000; font-weight: bold;">/</span>tmp
Deleting       demo<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>cache
Deleting       demo<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>pids
Deleting       demo<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>sessions
Deleting       demo<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>sockets
&nbsp;
Committed revision <span style="color: #000000;">4</span>.</pre></div></div>

<p>To end up, the only final step is not subversion the config for accessing the database.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>demo$ <span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:ignore <span style="color: #ff0000;">&quot;database.yml&quot;</span> config<span style="color: #000000; font-weight: bold;">/</span>
property <span style="color: #ff0000;">'svn:ignore'</span> <span style="color: #000000; font-weight: bold;">set</span> on <span style="color: #ff0000;">'config'</span>
&nbsp;
jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>cdemo$ <span style="color: #c20cb9; font-weight: bold;">svn</span> ci <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;Ignoring database.yml&quot;</span>
Sending        demo<span style="color: #000000; font-weight: bold;">/</span>config
&nbsp;
Committed revision <span style="color: #000000;">5</span>.
jsegura<span style="color: #000000; font-weight: bold;">@</span>ibook:~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>demo$</pre></div></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2007%2F06%2F22%2Fsubversioning-a-rails-app%2F&amp;title=Subversioning%20a%20Rails%20App" id="wpa2a_20" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2007_2F06_2F22_2Fsubversioning-a-rails-app_2F_amp_title=Subversioning_20a_20Rails_20App?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2007/06/22/subversioning-a-rails-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

