<?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>Binary Doodles &#187; Ruby on Rails</title>
	<atom:link href="http://nithinbekal.com/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://nithinbekal.com</link>
	<description>Ruby on Rails, Web 2.0, Wordpress and more...</description>
	<lastBuildDate>Fri, 30 Jul 2010 17:49:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rails: Avoid multiple level nested resource routes</title>
		<link>http://nithinbekal.com/2010/05/14/rails-avoid-multiple-level-nested-resource-routes/</link>
		<comments>http://nithinbekal.com/2010/05/14/rails-avoid-multiple-level-nested-resource-routes/#comments</comments>
		<pubDate>Fri, 14 May 2010 15:47:19 +0000</pubDate>
		<dc:creator>Nithin Bekal</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://nithinbekal.com/?p=335</guid>
		<description><![CDATA[While generating RESTful routes in rails, it is easy to get carried away and generate many levels of nested resources for every level of has_many associations. For instance, I recently wrote something like this in my routes file:
  # in config/routes.rb
  map.resources :first_resources do &#124;first&#124;
    first.resources :second_resources do &#124;second&#124;
  [...]]]></description>
			<content:encoded><![CDATA[<p>While generating RESTful routes in rails, it is easy to get carried away and generate many levels of nested resources for every level of has_many associations. For instance, I recently wrote something like this in my routes file:</p>
<pre>  # in config/routes.rb
  map.resources :first_resources do |first|
    first.resources :second_resources do |second|
      second.resources :third_resources
    end
  end</pre>
<p>Here FirstResouce has_many SecondResources and SecondResource has_many ThirdResources. Now imagine how you would get the path to edit the third level resource. You&#8217;d have to write something like this:</p>
<pre>edit_first_resource_second_resource_third_resource_path(@first_resource, \
    @second_resource, @third_resource)</pre>
<p>Yes, that&#8217;s how bad it would look when the routes are written for the innermost resource in the routes.</p>
<p>When I found myself doing something similar a few days ago, I decided to look for a better way to do this, and it amazes me how I missed this simple (and universally used) approach to writing nested resource routes.</p>
<p>Let&#8217;s take the example of a school where each course would have many batches, and each batch would have many exams. </p>
<pre># app/models/course.rb
class Course < ActiveRecord::Base
  has_many :batches
end

# app/models/batch.rb
class Batch < ActiveRecord::Base
  belongs_to :course
  has_many :exams
end

# exam.rb
class Exam < ActiveRecord::Base
  belongs_to :batch
end</pre>
<p>Writing the routes with two levels of nesting would give me something like this:</p>
<pre>  # config/routes.rb
  map.resources :courses do |course|
    course.resources :batches do |batch|
      batch.resources :exams
    end
  end</pre>
<p>The route to edit an exam object @exam (belonging to batch @batch which in turn belongs to course @course) would look like this:</p>
<pre>edit_course_batch_exam_path(@course, @batch, @exam)</pre>
<p>This is way too long and rather than make it easy to understand the path, it is going to make it even more confusing when somebody tries to understand the path. The url is going to be something like <code>http://domain.com/courses/1/batches/1/exams/1/edit</code>.</p>
<p>The best solution in this case is to nest the resources to just one level so that batches a nested within courses (e.g. http://domain.com/courses/1/batches) and exams are nested only within batches (e.g. http://domain.com/batches/1/exams). Using a rails shortcut to define nested routes, we could write the routes like this:</p>
<pre>  # in config/routes.rb
  map.resources :courses, :has_many => :batches
  map.resources :batches, :has_many => :exams</pre>
<p>Now if you wanted to edit an exam resource, you could just write <code>edit_batch_exam(@batch, @exam)</code> without having to worry about specifying the course object in the route. If you needed the course object within the exams controller, all you need to do is write a before filter that loads the batch and course as shown here:</p>
<pre># app/controllers/exams_controller.rb
class ExamsController < ApplicationController
  before_filter :load_batch_and_course

  # RESTful actions

  private
  def load_batch_and_course
    @batch = Batch.find(params[:batch_id])
    @course = @batch.course
  end
end</pre>
<p>Since we can get the course_id from the batch, there is no need for us to have the course_id in the route. This makes the routes much easier to understand.</p>
<p>Have you come across any situation where nesting more than one level is absolutely necessary? (I couldn't imagine any such situation off the top of my head.) How many levels of nested resources are okay with you? Do leave a comment and tell me what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://nithinbekal.com/2010/05/14/rails-avoid-multiple-level-nested-resource-routes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RubyConf India 2010</title>
		<link>http://nithinbekal.com/2010/03/27/rubyconf-india-2010-2/</link>
		<comments>http://nithinbekal.com/2010/03/27/rubyconf-india-2010-2/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 15:24:51 +0000</pubDate>
		<dc:creator>Nithin Bekal</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[RubyConf India]]></category>

		<guid isPermaLink="false">http://nithinbekal.com/?p=262</guid>
		<description><![CDATA[Those of you following this blog or my twitter stream probably know already that I spent last weekend attending RubyConf India in Bangalore. The conference was a huge success and I&#8217;m sure it helped inspire a lot of newbies like me.
Day 1
Along with the rest of the team from Foradian, I took a bus to [...]]]></description>
			<content:encoded><![CDATA[<p>Those of you following this blog or <a href="http://twitter.com/nithinbekal">my twitter stream</a> probably know already that I spent last weekend attending RubyConf India in Bangalore. The conference was a huge success and I&#8217;m sure it helped inspire a lot of newbies like me.</p>
<p><strong>Day 1</strong></p>
<p>Along with the rest of the team from Foradian, I took a bus to Bangalore the night before the conference and promptly got late and missed the kick off to the conference by Roy Singham.</p>
<p><strong>Ola Bini</strong> presented a keynote on the present and future of programming languages. Despite the fact that we had to struggle to keep up with the references to languages we hadn&#8217;t heard of, Ola kept the talk very interesting.</p>
<div class="wp-caption alignright" style="width: 298px"><img class="  " title="with-obie-fernandez-at-rubyconf-india-2010" src="http://lh4.ggpht.com/_SPbUIiu4sfA/S6dVSAYYMoI/AAAAAAAACaE/hANZi3V5AoA/s800/Image%28196%29.jpg" alt="Aslam and I with Obie Fernandez at RubyConf India 2010" width="288" height="216" /><p class="wp-caption-text">Me and Aslam with Obie Fernandez at RubyConf India 2010</p></div>
<p>Ola&#8217;s talk was followed by a session by <strong>Obie Fernandez</strong> titled <em>&#8220;Blood, Sweat and Rails 2010&#8243;</em>. Obie was funny and controversial, and even got rebuked for &#8220;abusive language&#8221;. (Aw, c&#8217;mon organizers&#8230; you can&#8217;t invite someone to speak and then shout at them.) He spoke about agile and Hashrocket and shared a lot of anecdotes about his work in Hashrocket. There were plenty of funny pictures from Hashrocket offices and one or two from the movie 3 Idiots that got the crowd roaring with laughter.</p>
<p>In the afternoon, <strong>Matz</strong> joined in through video conference and spoke about Ruby. To hear the story of Ruby from the guy who created it was&#8230; well&#8230; awesome. He spoke about Ruby&#8217;s history and also the future of the language. Matz even mentioned that work on Ruby 2 will start in August after version 1.9.2 is completed.</p>
<p>I attended a couple of other talks on the day — <em>Ruby on Rails versus Django &#8211; A newbie Web Developer&#8217;s Perspective</em> by Shreyank Gupta and <em>Mortal Kombat: Developer vs. Designer</em> by Kapil Mohan and Arun J. Having two tracks meant that I had to sacrifice some very interesting talks in favor of others. Hopefully the videos will be uploaded soon and I&#8217;ll be able to catch the other talks.</p>
<p><strong>Day 2</strong></p>
<div id="attachment_275" class="wp-caption alignright" style="width: 298px"><a href="http://nithinbekal.com/blog/wp-content/uploads/2010/03/210320101263-copy.jpg"><img class="size-full wp-image-275  " title="with-nick-sieger-at-rubyconf-india-2010" src="http://nithinbekal.com/blog/wp-content/uploads/2010/03/210320101263-copy.jpg" alt="" width="288" height="216" /></a><p class="wp-caption-text">With Nick Sieger at RubyConf India 2010.</p></div>
<p>The first speaker on the second day was <strong>Nick Sieger</strong> from Engine Yard who spoke about the features of Rails 3. It was a great talk, and I am feeling more and more guilty about not having tried Rails 3 yet.</p>
<p><strong>Pradeep Elankumaran</strong> then spoke about entrepreneurship in India and it was one of the most interactive sessions in RubyConf. He gave quite a few pointers on how to go about building web applications very quickly and about the tools they use at Intridea. I probably scribbled more on the notepad in this session than in all the other sessions combined.</p>
<p>In the afternoon, we attended a talk by <strong>Sarah Taraporewalla</strong> on the drawback of current view templating systems followed by another talk by Pradeep Elankumaran on Message Queuing in Ruby.</p>
<p><strong>Brian Guthrie</strong>&#8217;s talk, <em>&#8220;Advanced Ruby Idioms So Clean You Can Eat Off Of Them&#8221;</em>, although a bit too advanced for newbies like us, was still very interesting. Brian kept the talk very lively with a lot of jokes — many of which the audience sadly missed. The sequence of slides at the end of the presentation with alternate slides in red and green backgrounds with &#8220;TEST&#8221; written in bold letters made a huge impact on the team on the importance of testing. If only I&#8217;d know this method would work so efficiently, I&#8217;d have done that long ago. :D</p>
<p>After Brian&#8217;s talk, we went to see Arvind&#8217;s presentation on Project Fedena which started a little late and therefore we had to run over to the other hall to catch Roy Singham&#8217;s closing note.</p>
<p><strong>Ruby v/s Rails</strong></p>
<p>Roy spoke about agile, software development, the ruby community and entrepreneurship. Towards the end of the talk, there was a disagreement between him and Obie Fernandez over the attitudes in the rails community. I have to agree with Obie that you cannot blame the entire Rails community for incidents like <a href="http://gadgetopia.com/post/6794">that presentation at the Golden Gate Ruby conference</a>. In my opinion, Roy&#8217;s ranting against the rails community is only going to leave the community more polarized than before.</p>
<p><strong>Women&#8217;s attendance at RubyConf</strong></p>
<p>One thing that shocked me was when Roy Singham mentioned that the attendance of women at this RubyConf — 28 — was the highest ever at any RubyConf. I always knew this wasn&#8217;t a particularly women-friendly environment, but I didn&#8217;t know things were so bad that a 7% attendance would break all records for Ruby conferences.</p>
<p><strong>Conclusion</strong></p>
<p>Overall, it was a fantastic experience. To get an opportunity to actually speak to guys like Obie Fernandez, Satish Talim and Ola Bini is something I wouldn&#8217;t have believed possible a few months ago. I&#8217;m still mad at the organizers for interrupting Obie&#8217;s talk, but at least we have to be thankful that we got to hear all these people speak.</p>
<p>Did you attend RubyConf? If so, what did you think of the event? What&#8217;s your opinion on the whole ruby v/s rails controversy? What about the censoring of respected speakers? What did you like best about the event? Please do leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://nithinbekal.com/2010/03/27/rubyconf-india-2010-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Bukluv enters beta</title>
		<link>http://nithinbekal.com/2010/03/19/bukluv-enters-beta/</link>
		<comments>http://nithinbekal.com/2010/03/19/bukluv-enters-beta/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 15:23:54 +0000</pubDate>
		<dc:creator>Nithin Bekal</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Bukluv]]></category>

		<guid isPermaLink="false">http://nithinbekal.com/?p=251</guid>
		<description><![CDATA[Bukluv is the idea for an application that I, along with Mohammed Aslam, came up with a few months ago. It is a social networking site for book lovers and allows registered users to post short reviews that are limited to 250 characters.
We&#8217;ve been playing around with a very basic version of the app in [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bukluv.com/">Bukluv</a> is the idea for an application that I, along with <a href="http://aslam-revised.blogspot.com/">Mohammed Aslam</a>, came up with a few months ago. It is a social networking site for book lovers and allows registered users to post short reviews that are limited to 250 characters.</p>
<p>We&#8217;ve been playing around with a very basic version of the app in development for some time now, but we decided to code it again from scratch sometime in February, and try to release it by the first of March. Things got delayed a little bit and we finally deployed it last weekend.</p>
<p>As of now, the application is very basic, and doesn&#8217;t even let users add books that aren&#8217;t on our database. We even left out commenting on others&#8217; reviews until we could sort out the user interface, so the &#8220;social&#8221; part of this social networking site is still missing. However, we&#8217;re planning to roll out these features over the next few weeks, and we&#8217;ll start working on it again once we&#8217;ve returned from Bangalore after RubyConf ndia 2010.</p>
<p>Working on our own application has been great fun so far. But working on your own projects during spare time can be a difficult thing when you have a day job. It&#8217;s easy to put too much energy into your own project and then your projects at work will suffer. This is why we&#8217;ve been adding features very slowly and not work too many hours on this, so we don&#8217;t lose focus at the office.</p>
<p>Please do take a look at <a href="http://bukluv.com/">bukluv</a> if you&#8217;re a book lover. We&#8217;d love the feedback. Let us know what you think we&#8217;re doing wrong with the application.</p>
<p>I&#8217;m off to catch a bus to Bangalore now. Feeling so excited about my first RubyConf. There are some great presentations scheduled, and of course, there&#8217;s the one about <a href="http://www.fedena.com/">Project Fedena</a>. Please do leave a comment here if you took a look at bukluv, and I&#8217;ll reply when I get back from Bangalore.</p>
]]></content:encoded>
			<wfw:commentRss>http://nithinbekal.com/2010/03/19/bukluv-enters-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails: SEO friendly URLs using to_param</title>
		<link>http://nithinbekal.com/2010/03/01/rails-seo-friendly-urls-using-to_param/</link>
		<comments>http://nithinbekal.com/2010/03/01/rails-seo-friendly-urls-using-to_param/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 18:28:28 +0000</pubDate>
		<dc:creator>Nithin Bekal</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://nithinbekal.com/?p=233</guid>
		<description><![CDATA[I&#8217;ve wondered about how rails websites like Railscasts created SEO friendly URLs. I read this post by Obie Fernandez which explains how to do this.
I&#8217;ve never had to use SEO friendly URLs in my projects so far and I assumed that generating these URLs is very complicated and some plugin might be at work. And [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve wondered about how rails websites like <a href="http://railscasts.com/">Railscasts</a> created SEO friendly URLs. I read <a href="http://www.jroller.com/obie/entry/seo_optimization_of_urls_in">this post by Obie Fernandez</a> which explains how to do this.</p>
<p>I&#8217;ve never had to use SEO friendly URLs in my projects so far and I assumed that generating these URLs is very complicated and some plugin might be at work. And like always, Rails proved me wrong and I&#8217;m amazed at how simple this is.</p>
<p>Suppose you had a RESTful resource called posts that had title and content fields. If you wanted the post page URLs to contain text from the title, you just have to add this <code>to_param</code> method to the Post model:</p>
<pre>
class Post
  # other stuff here

  def to_param
    "#{id}-#{title.gsub(/[^a-z0-9]+/i, '-')}"
  end
end
</pre>
<p>Now if you had a post whose title was &#8220;SEO friendly URLs&#8221;, and in your view you had <code>&lt;%= link_to @post.title, @post %&gt;</code> where @post is an instance of the Post model representing the &#8220;SEO friendly URLs&#8221; post. This will generate the following path: <code>/posts/1-SEO-friendly-URLs</code>.</p>
<p>As explained in Obie&#8217;s post, this will only work if you pass an instance of Post as the id parameter and the actual id itself. You don&#8217;t have to change anything in the controller to make this work.</p>
<p>This is just another one of those little tricks I discovered in rails that originally looked difficult but is actually incredibly easy to accomplish.</p>
]]></content:encoded>
			<wfw:commentRss>http://nithinbekal.com/2010/03/01/rails-seo-friendly-urls-using-to_param/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RubyConf India 2010</title>
		<link>http://nithinbekal.com/2010/02/11/rubyconf-india-2010/</link>
		<comments>http://nithinbekal.com/2010/02/11/rubyconf-india-2010/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 15:19:41 +0000</pubDate>
		<dc:creator>Nithin Bekal</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[RubyConf India]]></category>

		<guid isPermaLink="false">http://nithinbekal.com/?p=216</guid>
		<description><![CDATA[I registered for RubyConf India 2010 this morning. I was interested in the event anyway, but when the proposal for a presentation on Project Fedena by Arvind was selected that definitely made up my mind. The rest of Team Fedena &#8211; developers Aslam and Ralu, and designer Jaseem &#8211; have also decided to travel to [...]]]></description>
			<content:encoded><![CDATA[<p>I registered for RubyConf India 2010 this morning. I was interested in the event anyway, but when the proposal for a presentation on Project Fedena by Arvind was selected that definitely made up my mind. The rest of Team Fedena &#8211; developers Aslam and Ralu, and designer Jaseem &#8211; have also decided to travel to Bangalore for the event to be held on March 20-21.</p>
<p>This is the first edition of RubyConf India and there were surprisingly few tickets &#8212; just 150. I was worried we wouldn&#8217;t manage to get tickets, but registering early in the morning helped. From the number of mentions it has been getting on twitter today, I guess it will be sold out before the end of the day.</p>
<p>Apart from keynote addresses by Chad Fowler and Ola Bini, there are quite a few big names speaking at the event. So I&#8217;m even more delighted that Fedena will also be presented there. I&#8217;ve been working on the Fedena developer community all week and we&#8217;ll hopefully have projectfedena.org ready by the time we leave for Bangalore.</p>
<p style="text-align: center;"><a href="http://rubyconfindia.org"><img class="aligncenter" src="http://rubyconfindia.org/stock/rubyconf-badges/RubyConf2010/270X185_attending.jpg" alt="I'm attending RubyConf India 2010" width="270" height="185" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://nithinbekal.com/2010/02/11/rubyconf-india-2010/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rails: Thinking Sphinx plugin for search</title>
		<link>http://nithinbekal.com/2009/12/25/rails-thinking-sphinx-plugin-for-search/</link>
		<comments>http://nithinbekal.com/2009/12/25/rails-thinking-sphinx-plugin-for-search/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 11:20:57 +0000</pubDate>
		<dc:creator>Nithin Bekal</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Rails plugins]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://nithinbekal.com/?p=179</guid>
		<description><![CDATA[Just a couple of weeks into being a rails developer, I made the one really, really, really big blunder &#8212; I used a find_by_sql in a search page. (Oh, please&#8230; stop booing. I was a newbie then.) Now, I&#8217;ve realized that I might have to modify the search to add yet another column, and well&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Just a couple of weeks into being a rails developer, I made the one really, really, really big blunder &#8212; I used a find_by_sql in a search page. (Oh, please&#8230; stop booing. I was a newbie then.) Now, I&#8217;ve realized that I might have to modify the search to add yet another column, and well&#8230; extending a find_by_sql query for a fourth column (yeah, it was searching 3 columns already) would be stupid and incredibly ugly.</p>
<p>I came across Thinking Sphinx plugin for full text search over MySQL and Postgres databases. It connects ActiveRecord to the Sphinx search engine and lets you perform searches over multiple columns and even multiple models easily.</p>
<p>Things went rather smoothly when I tried using the plugin and I managed to set it up and running within a few minutes. Here&#8217;s how I set up an example application and tested sphinx.</p>
<ol>
<li> Download sphinx from <a href="http://sphinxsearch.com/downloads.html">here</a>. If you&#8217;re on windows, you just have to extract the exe files to ruby/bin directory. On, Linux/Mac, you&#8217;ll have to compile the source. (See instructions <a href="http://freelancing-god.github.com/ts/en/installing_sphinx.html" target="_blank">here</a>.)</li>
<li> Install the thinking_sphinx plugin like this:
<pre>script/plugin install git://github.com/freelancing-god/thinking-sphinx.git</pre>
<p>You might run into trouble on Windows with the script/plugin install, so you can use this instead.</p>
<pre>ruby script/plugin install http://github.com/freelancing-god/thinking-sphinx.git/</pre>
</li>
<li> For this example, let&#8217;s quickly set up a Post model through scaffolding.
<pre>ruby script/generate scaffold Post title:string body:text</pre>
</li>
<li> Now we&#8217;ll set up the indexes for the posts model like this:
<pre>  define_index do
    indexes title, body
  end</pre>
</li>
<li> In the index method in PostsController, change <code>Post.all</code> to this:
<pre>Post.search(params[:search])</pre>
</li>
<li> Add a simple search form in articles/index.
<pre>
&lt;% form_tag posts_path, :method =&gt; 'get' do %&gt;
  &lt;p&gt;
    &lt;%= text_field_tag :search, params[:search] %&gt;
    &lt;%= submit_tag "Search", :name =&gt; nil %&gt;
  &lt;/p&gt;
&lt;% end %&gt;
</pre>
</li>
<li> Now we have to run a couple of rake commands to get sphinx to work. To get sphinx to process the data, run this rake task:
<pre>rake thinking_sphinx:index</pre>
<p>To start the sphinx server:</p>
<pre>rake thinking_sphinx:start</pre>
</li>
<li> Now if you search for something using the form, the page returns the posts matching your query.</li>
</ol>
<p>It also allows you to search across multiple models that are related. For example, if a post has many comments, you could change define_index to search comments as well.</p>
<pre>  define_index do
    indexes title, body
    indexes comments.body :as => :comments_body
  end</pre>
<p>Sphinx also has support for delta indexing, which means that rather than index the entire table, it can index only those rows that have been added since the last index. You need to schedule the indexing according to your application&#8217;s requirement. There&#8217;s a nice little gem called <a href="http://github.com/javan/whenever">whenever</a> that will allow you to schedule the rake tasks in ruby.</p>
<p>What plugins have you used for full text search in rails? Have you tried Sphinx? Or ferret or solr? I&#8217;ve mostly heard people saying sphnx is better than solr or ferret. What do you think?</p>
<p>Update. I&#8217;ve put the <a href="http://github.com/nithinbekal/sphinx_example">source code for this example on github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nithinbekal.com/2009/12/25/rails-thinking-sphinx-plugin-for-search/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rails: Importing data from spreadsheets into database</title>
		<link>http://nithinbekal.com/2009/12/09/rails-importing-data-from-spreadsheets-into-database/</link>
		<comments>http://nithinbekal.com/2009/12/09/rails-importing-data-from-spreadsheets-into-database/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 18:26:57 +0000</pubDate>
		<dc:creator>Nithin Bekal</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Rake]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://nithinbekal.com/?p=118</guid>
		<description><![CDATA[Recently I was trying to find ways to import data from excel spreadsheets into the database in a rails project. We needed to save the data from the client&#8217;s excel file into the database. Here&#8217;s how it can be done using a rake task.

The file will have to be in CSV format, so you&#8217;ll have [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was trying to find ways to import data from excel spreadsheets into the database in a rails project. We needed to save the data from the client&#8217;s excel file into the database. Here&#8217;s how it can be done using a rake task.</p>
<ol>
<li>The file will have to be in CSV format, so you&#8217;ll have to open it with any spreadsheet application like Microsoft Excel (or Google Docs in my case) and save it as CSV. Put the file in your project folder.
</li>
<li><code>FasterCSV</code> is a ruby gem that lets you easily parse CSV files and is a faster alternative to ruby&#8217;s standard CSV library. Install it using the command:
<pre>
gem install fastercsv
</pre>
</li>
<li>Create a rake task that reads the CSV file using the fastercsv gem and saves the data in the database. Your code should look something like this:
<pre>
namespace :db do

  desc "load user data from csv"
  task :load_csv_data  => :environment do
    require 'fastercsv'

    FasterCSV.foreach("data.csv") do |row|
      User.create(
        :user_name => row[0],
        :email => row[1],
        :password => row[2]
      )
    end
  end
end
</pre>
<p>You can replace the User model here with whatever model you&#8217;re importing from the CSV file.</li>
<li>Save the task as a rake file in lib/tasks folder and name it import_csv_data.rake or something to that effect.</li>
<li>Go to the shell and run the task by:
<pre>
rake db:load_csv_data
</pre>
</li>
</ol>
<p>When I came across this problem, my first reaction was to look for a ruby library that reads spreadsheets directly. But that&#8217;s a challenge for another day. For this particular project we can manually save the spreadsheets as CSV.</p>
<p>I did find a library called <code>roo</code> (<a href="http://roo.rubyforge.org/">http://roo.rubyforge.org/</a>) that can access the contents of a spreadsheet directly and it might be worth looking into if you need to read an uploaded spreadsheet directly.</p>
<p>Have you had to do something similar in your projects? What other method would you suggest to accomplish this task?</p>
]]></content:encoded>
			<wfw:commentRss>http://nithinbekal.com/2009/12/09/rails-importing-data-from-spreadsheets-into-database/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Setting up Ruby on Rails development environment with NetBeans on Windows</title>
		<link>http://nithinbekal.com/2009/09/19/setting-up-ruby-on-rails-development-environment-with-netbeans-on-windows/</link>
		<comments>http://nithinbekal.com/2009/09/19/setting-up-ruby-on-rails-development-environment-with-netbeans-on-windows/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 15:43:00 +0000</pubDate>
		<dc:creator>Nithin Bekal</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[IDEs and Editors]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[IDEs]]></category>
		<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://nithinbekal.com/2009/09/19/setting-up-ruby-on-rails-development-environment-with-netbeans-on-windows/</guid>
		<description><![CDATA[Find out how to set up ruby on rails development environment on windows.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve set up NetBeans for Ruby on Rails with NetBeans twice today &#8212; first at work for a friend who is moving to RoR development from PHP, and then at home where a dying hard disk forced me to get a new hard disk and install all the software I require all over again.</p>
<p>I realized that setting up a Rails environment might seem a daunting task for a newbie. Here&#8217;s a list of steps to get Ruby on Rails working on a windows machine. I use NetBeans with MySQL because I found the least trouble to set up.</p>
<ol>
<li>Go to <a href="http://www.ruby-lang.org">www.ruby-lang.org</a> and download the ruby one-click installer for Windows.</li>
<li>Install ruby using the one-click installer, and remember to select RubyGems when asked what components you want installed.</li>
<li>Download and install MySQL from <a href="http://dev.mysql.com/downloads/">http://dev.mysql.com/downloads/</a>.</li>
<li>You will need java to run NetBeans, so download java from <a href="http://www.java.com/en/">http://www.java.com/en/</a> and install.</li>
<li>Download the latest version (6.7 at the moment) of NetBeans from <a href="http://www.netbeans.org/">http://www.netbeans.org/</a>. You might choose the complete NetBeans package or the Ruby only version. Either of them will do.</li>
<li>Install rails for your ruby installation by using this command in the command line:
<pre>gem install rails</pre>
</li>
<li>You will also need the ruby MySQL driver to be installed to be able to use MySQL databases. For this, install the <code>mysql</code> gem by this command:
<pre>gem install mysql</pre>
</li>
<li>When I started NetBeans and created a new rails project, NetBeans asked me to update ruby gems from 1.3.1 to 1.3.2. Unfortunately, the one click installer is available only for Ruby 1.8.6 and contains gem version 1.3.1, so you&#8217;ll have to update rubygems using the command line:
<pre>gem update --system</pre>
</li>
</ol>
<p>That&#8217;s it&#8230; you can now use NetBeans as a rails development environment. I know that was a very long list of steps to get a rails IDE working, but it&#8217;s worth the trouble. Using ruby on rails as your development environment will make up for the effort required to set up the IDE.</p>
<p>What IDE do you use for rails development? When you were new to rails development, did you have trouble setting up a development environment? And in case you&#8217;re a newbie rails developer, is that how you got here?</p>
]]></content:encoded>
			<wfw:commentRss>http://nithinbekal.com/2009/09/19/setting-up-ruby-on-rails-development-environment-with-netbeans-on-windows/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>First impressions: Ruby Encoder for ruby source code encryption</title>
		<link>http://nithinbekal.com/2009/09/03/first-impressions-ruby-encoder-for-ruby-source-code-encryption/</link>
		<comments>http://nithinbekal.com/2009/09/03/first-impressions-ruby-encoder-for-ruby-source-code-encryption/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 17:50:00 +0000</pubDate>
		<dc:creator>Nithin Bekal</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://nithinbekal.com/2009/09/03/first-impressions-ruby-encoder-for-ruby-source-code-encryption/</guid>
		<description><![CDATA[About a week ago at work, I was asked to evaluate Ruby Encoder, an application to encrypt the source code of your ruby application.
Normally, you wouldn&#8217;t want to encrypt the source code of your ruby applications. The code resides on your server and there&#8217;s no way anyone else can access it. However, if you are [...]]]></description>
			<content:encoded><![CDATA[<p>About a week ago at work, I was asked to evaluate <a href="http://www.rubyencoder.com/index.html">Ruby Encoder</a>, an application to encrypt the source code of your ruby application.</p>
<p>Normally, you wouldn&#8217;t want to encrypt the source code of your ruby applications. The code resides on your server and there&#8217;s no way anyone else can access it. However, if you are going to allow others to host your code on their own servers, you might want to obfuscate your code so that nobody can see it.</p>
<p>I signed up for the free trial of Ruby Encoder and so far I&#8217;ve been impressed with how easy it is to set it up for use with the ruby on rails application I&#8217;m working on. It took me less than ten minutes to encrypt all the ruby files and run the project on the development machine.</p>
<p>Ruby Encoder works by encrypting the ruby source into bytecode and then decrypts this encrypted code using a loader (which is an compiled ruby module) and sends it to the interpreter. This way, all anyone will get to see in your .rb files will be a lot of gibberish and a call to the loader function.</p>
<p>I haven&#8217;t really had the time to check it out thoroughly and I don&#8217;t know how well it will work in production, but right now it looks like the best option (and probably the only option?) for what I am trying to accomplish.</p>
<p>I was discussing Ruby Encoder with a friend and one very valid argument that came up was about how far such software could help if someone really wanted to clone our application. If someone wanted to steal our code, they most likely would be capable of coding the application by themselves by looking at the views of the application. So is it really worth the trouble to use an application like Ruby Encoder just to make things a little bit more difficult for them?</p>
<p>What do you think of ruby source code encryption? Have you ever used Ruby Encoder or similar products for any of your projects? If so, how well has it worked for you? Do you think using such an application is a good idea?</p>
<p>What method would you employ if you had to ensure that your ruby code remained closed source?</p>
]]></content:encoded>
			<wfw:commentRss>http://nithinbekal.com/2009/09/03/first-impressions-ruby-encoder-for-ruby-source-code-encryption/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rails: &quot;500 &#8211; Internal server error&quot; caused by error in application.rb</title>
		<link>http://nithinbekal.com/2009/08/20/rails-500-internal-server-error-caused-by-error-in-application-rb/</link>
		<comments>http://nithinbekal.com/2009/08/20/rails-500-internal-server-error-caused-by-error-in-application-rb/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 15:32:00 +0000</pubDate>
		<dc:creator>Nithin Bekal</dc:creator>
				<category><![CDATA[Rants]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://nithinbekal.com/2009/08/20/rails-500-internal-server-error-caused-by-error-in-application-rb/</guid>
		<description><![CDATA[Today, while working on my Ruby on Rails project, I got a &#8220;500 &#8211; Internal server error&#8221; page soon after I tried to run the project after running a migration. There was nothing else on the screen except for that one line.
I tried a few things, like restarting NetBeans, and opening another project to see [...]]]></description>
			<content:encoded><![CDATA[<p>Today, while working on my Ruby on Rails project, I got a &#8220;500 &#8211; Internal server error&#8221; page soon after I tried to run the project after running a migration. There was nothing else on the screen except for that one line.</p>
<p>I tried a few things, like restarting NetBeans, and opening another project to see if the problem was with my Ruby installation. (Other projects were running fine, so the problem wasn&#8217;t with Ruby.) I even tried running the project from another desktop, getting the same 500 error.</p>
<p>Finally, I did the one thing that I should have done first &#8211; checking the development log file. There I found that the problem was a tiny bit of buggy code in the application.rb file that was stopping the project from initializing properly. And because the application failed to initialize, I wasn&#8217;t getting those detailed error messages that I&#8217;m so familiar with.</p>
<p>Have you done something so stupid while developing an application? Forgetting to look at the first place where you could have spotted the problem and instead wasting an hour theorizing about what could be causing the problem?</p>
]]></content:encoded>
			<wfw:commentRss>http://nithinbekal.com/2009/08/20/rails-500-internal-server-error-caused-by-error-in-application-rb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
