<rss version="2.0">
  <channel>
    <title>YARB - Yet Another Rails Blog</title>
    <link>http://shanti.railsblog.com</link>
    <description>RSS feed for YARB</description>
    <item>
      <title>Stop, Haml Time: Adding Haml and Sass Bundles in TextMate</title>
      <guid isPermaLink="true">http://shanti.railsblog.com/rails/stop-haml-time-adding-haml-and-sass-bundles-i</guid>
      <link>http://shanti.railsblog.com/rails/stop-haml-time-adding-haml-and-sass-bundles-i</link>
<description><![CDATA[First cd to your operating system's /Library folder (*not* ~/Library):
<pre>cd /Library/Application Support/TextMate/Bundles</pre>

Install the Haml bundle with:
<pre>sudo svn co http://macromates.com/svn/Bundles/trunk/Bundles/Ruby%20Haml.tmbundle</pre>

Install the Sass bundle with:
<pre>sudo git clone git://github.com/aussiegeek/ruby-sass-tmbundle.git "Ruby Sass.tmbundle"</pre>

Note: cloning the sass bundle without an additional directory parameter will not work.  TextMate expects bundles to have the format "bundlename.tmbundle". 
 ]]></description>      <pubDate>Fri, 07 Nov 2008 19:35:07 +0000</pubDate>
    </item>
    <item>
      <title>Updating Submodules via Git</title>
      <guid isPermaLink="true">http://shanti.railsblog.com/rails/updating-submodules-via-git-5277</guid>
      <link>http://shanti.railsblog.com/rails/updating-submodules-via-git-5277</link>
<description><![CDATA["This article":http://woss.name/2008/04/09/using-git-submodules-to-track-vendorrails/ covers this topic in depth.

I've switched to using git submodules to manage external plugins.  Recently I forked the "rbet":http://github.com/sbraford/rbet/tree/master library and added it to a project via git submodules:
<pre>git submodule add git://github.com/sbraford/rbet.git vendor/rbet</pre>

But wait, I have new changes in my rbet library that I'd like to pull into my app:
<pre>git submodule update</pre>

No dice.

Git submodules are tied to the specific revision of the external repository at the time of checkout.  Once more, with enthusiasm! 

_Git submodules are tied to the specific revision of the external repository at the time of checkout._

To update rbet to the latest version in this example, I had to do a:
<pre>cd vendor/rbet
git remote update
git merge origin/master</pre>

Then to make sure these changes get reflected in my main app:
<pre>cd ../..
git add .
git commit -a -m "updated rbet to latest"
git push</pre>

And presto, we have successfully ninja-unicorned our git submodule.
 
 ]]></description>      <pubDate>Mon, 20 Oct 2008 18:16:06 +0000</pubDate>
    </item>
    <item>
      <title>DRYing CRUDdy Views: Filling the gap Between Streamlined &amp; Custom</title>
      <guid isPermaLink="true">http://shanti.railsblog.com/rails/drying-cruddy-views-filling-the-gap-between-s-75</guid>
      <link>http://shanti.railsblog.com/rails/drying-cruddy-views-filling-the-gap-between-s-75</link>
<description><![CDATA[Some rails projects have components that are little more than glorified CRUD interfaces to a database.

In this particular case, I'm working on a backend administration tool, bolting onto some legacy data.

Parts of the app need to be custom, with a nice GUI using in place editing, etc.  But other parts are just a dumb listing of the data, with editing ability.

ActiveRecord::Base has a class method 'columns' which returns all of the metadata for the class' database columns.

Here are a few helpers that you can put in a file, e.g. 'extensions.rb' in your config/initializers directory (Rails 2.1):

<pre>
module ColumnHelperExtensions
  
  def field_columns
    columns.select {|c| [:string, :integer].include?(c.type) && !c.primary && !c.name.include?('id') }
  end

  def date_columns
    columns.select {|c| :date == c.type }
  end

  def boolean_columns
    columns.select {|c| :boolean == c.type }
  end

end

class ActiveRecord::Base
  class << self
    include ColumnHelperExtensions
  end
end
</pre>

Your controllers will behave just as normal CRUD (e.g. scaffolded-style) rails controllers.

Here is an example edit.html.erb:

<pre>
<h2>Editing <%= @foo.name %></h2>

<% form_for @foo do |f| %>
  <%= error_messages_for 'foo' %>
  <table class="standard_form">
    <%= render :partial => 'shared/generic_form', :locals => {:f => f, :klass => SparqUser} %>
  </table>
  <%= submit_tag "Update Foo &raquo;" %>
<% end %>
</pre>

Then in 'shared/_generic_form.html.erb' we tie it all together:

<pre>
<% klass.field_columns.each do |field| %>
  <tr>
    <td class="first"><%= f.label(field.name) %></td>
    <td><%= f.text_field(field.name) %></td>
  </tr>
<% end %>

<% klass.date_columns.each do |field| %>
  <tr>
    <td class="first"><%= f.label(field.name) %></td>
    <td><%= f.date_select(field.name) %></td>
  </tr>
<% end %>

<% klass.boolean_columns.each do |field| %>
  <tr>
    <td class="first"><%= f.label(field.name) %></td>
    <td><%= f.check_box(field.name) %></td>
  </tr>
<% end %>
</pre>

When facing the task of maintaining views for a table with 20+ columns, I find this approach, at the very least, a good way to bootstrap a CRUD interface without lots of code bloat.

Note: for this to be effective, your columns have to be named at least somewhat sensibly.  If you have a column titled 'event_date', this gets labeled 'Event date'.  Obviously a column named 'trlf_widget_gzy' will not make much sense to end users when humanized. 
 ]]></description>      <pubDate>Fri, 10 Oct 2008 03:09:18 +0000</pubDate>
    </item>
    <item>
      <title>Global Incrementor for Value Uniqueness</title>
      <guid isPermaLink="true">http://shanti.railsblog.com/rails/global-incrementor-for-value-uniqueness-8520</guid>
      <link>http://shanti.railsblog.com/rails/global-incrementor-for-value-uniqueness-8520</link>
<description><![CDATA[In several apps I've worked on, we've wanted a way to create a unique string.  For example, users cannot have duplicate email addresses.  So when creating many users via the Factory pattern, email addresses inevitably end up being something like "barney#{rand(1000)}@foo.org".

This always leads to problems.  UUIDs can be handy but then you have a 30 character long email address.

Why not just a global, app-level incrementor? (utilizing the Singleton pattern)

It will always output a unique integer, starting with the number 1.  Multiple objects can use this, so long as they do not require "random" integers to be in a row, but rather simply unique.

Enough talk.  Here's the code:
<pre>
module Incrementor
  
  def self.next
    @counter ||= Incrementor::Counter.new
    @counter.next
  end

  class Counter
    def initialize
      @i = 0
    end
    def next
      @i += 1
    end
  end
  
end
</pre>

In rails, you can throw that as 'incrementor.rb' in your config/initializers folder.

Usage:
<pre>
=> Incrementor.next
=> 1
=> Incrementor.next
=> 2
...
</pre>
 
 ]]></description>      <pubDate>Thu, 09 Oct 2008 17:14:30 +0000</pubDate>
    </item>
    <item>
      <title>svn info equivalent in git</title>
      <guid isPermaLink="true">http://shanti.railsblog.com/rails/svn-info-equivalent-in-git-9887</guid>
      <link>http://shanti.railsblog.com/rails/svn-info-equivalent-in-git-9887</link>
<description><![CDATA[When using Subversion, the command 'svn info' handily displays various metadata about your project, such as remote svn URL, etc.

Nothing exactly matches that in git, but to see the remote URL, you can do a:
<pre>git remote -v</pre>

Which will display something like:
<pre>origin  deploy@foo.githost.com:~/project</pre> 
 ]]></description>      <pubDate>Fri, 03 Oct 2008 18:32:45 +0000</pubDate>
    </item>
    <item>
      <title>New RSS Feed URL</title>
      <guid isPermaLink="true">http://shanti.railsblog.com/rails/new-rss-feed-url-7606</guid>
      <link>http://shanti.railsblog.com/rails/new-rss-feed-url-7606</link>
<description><![CDATA[After switching blogging engines, this blog now has a new RSS feed URL:

http://shanti.railsblog.com/posts.xml

Using Rails 2.x's new 'respond_to' to keep controller's DRY. 
 ]]></description>      <pubDate>Fri, 03 Oct 2008 18:30:30 +0000</pubDate>
    </item>
    <item>
      <title>Goodbye Mephisto, Hello Custom Blogging Platform</title>
      <guid isPermaLink="true">http://shanti.railsblog.com/rails/goodbye-mephisto-hello-custom-blogging-platfo-866</guid>
      <link>http://shanti.railsblog.com/rails/goodbye-mephisto-hello-custom-blogging-platfo-866</link>
<description><![CDATA[It would be nice if One Blogging Engine to Rule them All would emerge for Rails, like WordPress has become for PHP.

The problem is, rails makes it too easy just to roll your own.

I'm now blogging from a custom blog platform, complete with support for multiple blogs / domains / themes / etc.

Comments are checked against Akismet.  I should note that some shortcuts could be had due to the fact that this app is for internal (read: my own) use only.  Thus, we don't get too fancy with Liquid templating engines, etc.

Sorry - legacy comments & categories were lost in the conversion (I'm just too lazy to port everything over), as well as some posts.

Just like everyone seems to end up rolling their own MVC framework for PHP, it seems too people will just end up rolling their own blog engine for Rails. 
 ]]></description>      <pubDate>Fri, 03 Oct 2008 02:38:49 +0000</pubDate>
    </item>
    <item>
      <title>Ruby Daisy-Chaining for Fun &amp; Profit</title>
      <guid isPermaLink="true">http://shanti.railsblog.com/rails/ruby-daisychaining-for-fun-profit</guid>
      <link>http://shanti.railsblog.com/rails/ruby-daisychaining-for-fun-profit</link>
<description><![CDATA[p=. !http://shanti.railsblog.com/assets/2007/10/10/daisy_cat.jpg!



One of the things I love about Ruby is the ability to easily daisy-chain several functions together.  This feature is by no means unique to Ruby, but here I'll show how one might do this the Ruby way.



You have an array representing days of the week, indexed by 0 - 7, that you get back from a web post as strings.



<pre>days = params[:days] # {"5" => "1", "6" => "1", "2" => "1"}</pre>



But we want the keys as an array of integers in sorted order.



One way would be:



<pre>keys = days.keys

sorted = keys.sort

ints = []

sorted.each { |i| ints << i.to_i }

</pre>



Of course you wouldn't actually ever do it this way once you're familiar with Ruby idioms and are comfortable reading daisy-chained code (it can get ugly if abused!).



In Ruby, the above four lines can be condensed into the following one-liner:



<pre>ints = days.keys.sort.map(&:to_i)</pre>



Note: Rails monkeypatches collect/map to allow for the map(&:to_i) shortcut.



 
 ]]></description>      <pubDate>Fri, 19 Sep 2008 01:21:31 +0000</pubDate>
    </item>
    <item>
      <title>Must Explicitly Catch Timeout::Error</title>
      <guid isPermaLink="true">http://shanti.railsblog.com/rails/must-explicitly-catch-timeouterror-1405</guid>
      <link>http://shanti.railsblog.com/rails/must-explicitly-catch-timeouterror-1405</link>
<description><![CDATA[If you're using 'open-uri' to pull a random URL, you might get sporadic Timeout::Error's that are not being rescued, even if you have something like:

<pre>

    begin

      @raw = open(@url)

    rescue StandardError => e

      return false, "Timeout or other Error fetching feed"

    end

</pre>



Adding an explicit rescue for the Timeout::Error did the trick. (this is due to it being a subclass of Interrupt...)



<pre>

    begin

      @raw = open(@url)

    rescue StandardError => e

      return false, "Timeout or other Error fetching feed"

    rescue Timeout::Error

      return false, "Timeout error"

    end

</pre>

 
 ]]></description>      <pubDate>Fri, 12 Sep 2008 01:21:31 +0000</pubDate>
    </item>
    <item>
      <title>My First Time on Rails: Win32 Edition</title>
      <guid isPermaLink="true">http://shanti.railsblog.com/rails/my-first-time-on-rails-win32-edition</guid>
      <link>http://shanti.railsblog.com/rails/my-first-time-on-rails-win32-edition</link>
<description><![CDATA[This is a guide written for a friend who'll be using Rails on the Windows platform.



First, check out "these screencasts":http://www.rubyonrails.org/screencasts of people building actual rails apps.  For example, a rudimentary blogging application built in 15 minutes.



1. Download the "Ruby One-Click Installer":http://rubyforge.org/frs/?group_id=167&release_id=15923



It will be the first .exe file at the top.  As of this writing, it's: ruby186-26_rc2.exe



2. Install Rails via Ruby Gems



Ruby has a package manager called Gems.  It's a command-line tool (via DOS) called 'gem'.  The main usage is 'gem install X' where X is the name of the gem you want to install.



Need the "Twitter API library":http://twitter.com/ -- do a 'gem install twitter'



RSS processing? 'gem install simple-rss'



Facebook API integration? 'gem install rfacebook'



You get the idea.  For all of the available gems, head over to "Rubyforge":http://rubyforge.org and search for projects matching what you're looking to do.



To install rails via ruby gems, open a DOS prompt and enter the following:



<pre>

gem install rails --include-dependencies

</pre>



Sometimes gems will come with various install options (ruby, win32, and jruby).  You usually want the latest version of the gem, but for whatever OS you're using.  Windows users should pick the "win32" or windows versions of gems if the gem gives that option when installing.



3. Your First Rails App



Still in the DOS prompt, cd and/or make a directory where you want to keep your rails apps (C:\rails or whatever).



Next, let's say you want to call your app 'foojiggly', you'd do a:

<pre>

rails foojiggly

</pre>



This will create a new directory called 'foojiggly' and will place the skeleton of a Rails app into it for you.



Fire up your favorite text editor (I recommend "e - power of TextMate on Windows":http://www.e-texteditor.com/ or "EditPlus":http://www.editplus.com/ or  "RadRails":http://www.radrails.org/ ) and browse to your new app.



More to come later... 
 ]]></description>      <pubDate>Fri, 05 Sep 2008 01:21:31 +0000</pubDate>
    </item>
  </channel>
</rss>
