<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>@Lathi.net: Rails without ActiveRecord</title>
    <link>http://blog.lathi.net/articles/2007/08/08/rails-without-activerecord</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>On Life, Fatherhood, Christianity, and Computers</description>
    <item>
      <title>Rails without ActiveRecord</title>
      <description>&lt;p&gt;It&amp;#8217;s supposed to be easy to turn off ActiveRecord and have a database-less app.   The word is it&amp;#8217;s possible in rails 1.1.x, but not with vanilla rails 1.2.x.  To get your environment to load with rails 1.2, you still need a database.yml and the database created (even though it can be empty).  That seems a bit silly to me.  If you want a database-less app, you don&amp;#8217;t want to have to create a database and maintain a connection to that database. There&amp;#8217;s two problems I&amp;#8217;ve worked around to get a true database-less app with rails 1.2.&lt;/p&gt;


	&lt;p&gt;Theoretically all you have to do is set&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="constant"&gt;Rails&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Initializer&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;run&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;config&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
  &lt;span class="ident"&gt;config&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;frameworks&lt;/span&gt; &lt;span class="punct"&gt;-=&lt;/span&gt; &lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:active_record&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;The first problem is whiny nil requires ActiveRecord.  By default &lt;code&gt;config.whiny_nils&lt;/code&gt; is set to false.  However, both &lt;code&gt;config/environments/development.rb&lt;/code&gt; and &lt;code&gt;config/environments/test.rb&lt;/code&gt; both explicitly set it to true.  What I did was just comment out those assignments in the respective files.  Besides detecting when you call ActiveRecord methods on nil, whiny_nil will also detect when you call Array methods on nil.  By turning off whiny_nil, you loose the ability to easily detect when you&amp;#8217;re treating nil like an Array.&lt;/p&gt;


	&lt;p&gt;The second problem is that the Rails initializer requires AcriveRecord to load the observers.  This is documented in &lt;a href="http://dev.rubyonrails.org/ticket/6795"&gt;ticket #6795&lt;/a&gt; on the Rails trac.  It seems a bit kludgy, but what I did was redefine the load_observers method before I run the initializer in my environment.rb:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;require File.join(File.dirname(__FILE__), 'boot')

module Rails
  class Initializer
    def load_observers
      ActiveRecord::Base.instantiate_observers if 
          configuration.frameworks.include?(:active_record)
    end
  end
end

Rails::Initializer.run do |config|
...&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;There are several reasons for wanting a database-less rails app.  The ticket above references using something like &lt;span class="caps"&gt;CVS&lt;/span&gt; or Subversion as a datastore and using rails&amp;#8217; ActionPack to drive an interface.  I&amp;#8217;ll get into my own uses in another post soon.&lt;/p&gt;</description>
      <pubDate>Wed, 08 Aug 2007 08:02:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:f7bd77a3-0c48-47f7-8601-6a385a8b0258</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2007/08/08/rails-without-activerecord</link>
      <category>Ruby on Rails</category>
    </item>
    <item>
      <title>"Rails without ActiveRecord" by Pratik</title>
      <description>&lt;p&gt;config.frameworks == [:active_record]&lt;/p&gt;


	&lt;p&gt;You probably meant :&lt;/p&gt;


	&lt;p&gt;config.frameworks -= [:active_record]&lt;/p&gt;


	&lt;p&gt;Observer issue was fixed in edge : &lt;a href="http://dev.rubyonrails.org/changeset/6819" rel="nofollow"&gt;http://dev.rubyonrails.org/changeset/6819&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 08 Aug 2007 09:25:57 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ee535a58-6f78-4c39-aa1f-f72bc5d8239d</guid>
      <link>http://blog.lathi.net/articles/2007/08/08/rails-without-activerecord#comment-298</link>
    </item>
  </channel>
</rss>
