<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.5" -->
<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/"
	>

<channel>
	<title>Web On Rails</title>
	<link>http://webonrails.com</link>
	<description>Exploring RubyOnRails</description>
	<pubDate>Thu, 07 Aug 2008 11:52:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>
	<language>en</language>
			<item>
		<title>Installing gem on Leopard</title>
		<link>http://webonrails.com/2008/08/07/installing-gem-on-leopard/</link>
		<comments>http://webonrails.com/2008/08/07/installing-gem-on-leopard/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 11:47:38 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>Ruby</category>

		<category>gem</category>

		<category>Leopard</category>

		<guid isPermaLink="false">http://webonrails.com/2008/08/07/installing-gem-on-leopard/</guid>
		<description><![CDATA[May be you guys have noticed that when you try to install a new gem on your machine it says some thing like &#8220;Updating meta data for 500 gems&#8221; and display one dot per gem. These dots moves very slowly and stops in some time. 
I faced this situation many times and found a solution [...]]]></description>
			<content:encoded><![CDATA[<p>May be you guys have noticed that when you try to install a new gem on your machine it says some thing like &#8220;Updating meta data for 500 gems&#8221; and display one dot per gem. These dots moves very slowly and stops in some time. </p>
<p>I faced this situation many times and found a solution some where on net. I don&#8217;t remember the link but it worked.</p>
<p>According to that, you just need  to add:<br />
require &#8216;resolv-replace&#8217;<br />
as the first require in /usr/bin/gem file.</p>
<p>enjoy!!
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2008/08/07/installing-gem-on-leopard/feed/</wfw:commentRss>
		</item>
		<item>
		<title>When Ultrasphinx is used with polymorphic associations&#8230;</title>
		<link>http://webonrails.com/2008/08/07/when-ultrasphinx-is-used-with-polymorphic-associations/</link>
		<comments>http://webonrails.com/2008/08/07/when-ultrasphinx-is-used-with-polymorphic-associations/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 08:56:04 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>ultrasphinx</category>

		<guid isPermaLink="false">http://webonrails.com/2008/08/07/when-ultrasphinx-is-used-with-polymorphic-associations/</guid>
		<description><![CDATA[Lets first consider simple has_many and belongs_to associations as:

class Article < ActiveRecord::Base
  has_many :comments
end


class Comment < ActiveRecord::Base
  belongs_to :article
end

Now if you wish to index the title of associated article with comment for searching, you just need to add &#8221; is_indexed :fields => :body, :include => [{ :association_name => &#8216;article&#8217;, :field => &#8216;title&#8217;, :as=> [...]]]></description>
			<content:encoded><![CDATA[<p>Lets first consider simple has_many and belongs_to associations as:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
class Article < ActiveRecord::Base
  has_many :comments
end
</textarea>
<textarea name="code" class="ruby" cols="50" rows="10">
class Comment < ActiveRecord::Base
  belongs_to :article
end
</textarea>
<p>Now if you wish to index the title of associated article with comment for searching, you just need to add &#8221; is_indexed :fields => :body, :include => [{ :association_name => &#8216;article&#8217;, :field => &#8216;title&#8217;, :as=> &#8216;article_title&#8217;}] &#8221;</p>
<p>So, your comment model will look like:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
class Comment < ActiveRecord::Base
  belongs_to :article

  is_indexed :fields => :body,
             :include => [{ :association_name => 'article', :field => 'title', :as=> 'article_title'}]
end
</textarea>
<p>Setup ultrasphinx by issuing:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
rake ultrasphinx:bootstrap
</textarea>
<p>Now at rails console try:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
>> article = Article.create(:title => "This is the first article's title", :body => "Here comes first article's body.")
=> #<Article id: 1, title: "This is the first article's title", tagline: nil, type: nil, body: "Here comes first article's body.", created_at: "2008-08-07 07:47:53", updated_at: "2008-08-07 07:47:53">
>> article.comments
=> []
>> article.comments<<Comment.new(:body=>"first comment on first article. which says yahooo !!")
=> [#<Comment id: 1, body: "first comment on first article. which says yahooo !...", article_id: 1, created_at: "2008-08-07 07:48:47", updated_at: "2008-08-07 07:48:47">]
>> Comment.find :all
=> [#<Comment id: 1, body: "first comment on first article. which says yahooo !...", article_id: 1, created_at: "2008-08-07 07:48:47", updated_at: "2008-08-07 07:48:47">]
>> search = Ultrasphinx::Search.new(:query => "first article's title", :class_names => ['Comment']).run.results
=> [#<Comment id: 1, body: "first comment on first article. which says yahooo !...", article_id: 1, created_at: "2008-08-07 07:48:47", updated_at: "2008-08-07 07:48:47">]
</textarea>
<p>Simple, we have article and comment models with has_many belongs_to associations. Comments are indexed with their associated article title. So it can return comments if query matches with article&#8217;s titles.</p>
<p>Now, consider a case when we wish to change comment model to make it polymorphic. In that case our models will be look like:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
 class Article < ActiveRecord::Base
   has_many :comments, :as => :commentable, :dependent => :destroy
 end
</textarea>
<textarea name="code" class="ruby" cols="50" rows="10">
class Comment < ActiveRecord::Base
  belongs_to :commentable, :polymorphic => true
end
</textarea>
<p>Check at rails if associations are working fine:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
>> article = Article.create(:title => "First article title", :body => "here comes first artile's title")
=> #<Article id: 1, title: "First article title", tagline: nil, type: nil, body: "here comes first artile's title", created_at: "2008-08-07 08:12:31", updated_at: "2008-08-07 08:12:31">
>> comment = Comment.new(:body => "hello there, I am a comment")
=> #<Comment id: nil, body: "hello there, I am a comment", commentable_id: nil, commentable_type: nil, created_at: nil, updated_at: nil>
>> comment.commentable = article
=> #<Article id: 1, title: "First article title", tagline: nil, type: nil, body: "here comes first artile's title", created_at: "2008-08-07 08:12:31", updated_at: "2008-08-07 08:12:31">
>> comment.save
=> true
>> comment.reload
=> #<Comment id: 1, body: "hello there, I am a comment", commentable_id: 1, commentable_type: "Article", created_at: "2008-08-07 08:14:29", updated_at: "2008-08-07 08:14:29">
>> article.reload
=> #<Article id: 1, title: "First article title", tagline: nil, type: nil, body: "here comes first artile's title", created_at: "2008-08-07 08:12:31", updated_at: "2008-08-07 08:12:31">
>> article.comments
=> [#<Comment id: 1, body: "hello there, I am a comment", commentable_id: 1, commentable_type: "Article", created_at: "2008-08-07 08:14:29", updated_at: "2008-08-07 08:14:29">]
>> comment = Comment.new(:body => "hi there, this is second comment")
=> #<Comment id: nil, body: "hi there, this is second comment", commentable_id: nil, commentable_type: nil, created_at: nil, updated_at: nil>
>> article.comments<< comment
=> [#<Comment id: 1, body: "hello there, I am a comment", commentable_id: 1, commentable_type: "Article", created_at: "2008-08-07 08:14:29", updated_at: "2008-08-07 08:14:29">, #<Comment id: 2, body: "hi there, this is second comment", commentable_id: 1, commentable_type: "Article", created_at: "2008-08-07 08:15:34", updated_at: "2008-08-07 08:15:34">]
>> article.comments
=> [#<Comment id: 1, body: "hello there, I am a comment", commentable_id: 1, commentable_type: "Article", created_at: "2008-08-07 08:14:29", updated_at: "2008-08-07 08:14:29">, #<Comment id: 2, body: "hi there, this is second comment", commentable_id: 1, commentable_type: "Article", created_at: "2008-08-07 08:15:34", updated_at: "2008-08-07 08:15:34">] 
>> comment.commentable
=> #<Article id: 1, title: "First article title", tagline: nil, type: nil, body: "here comes first artile's title", created_at: "2008-08-07 08:12:31", updated_at: "2008-08-07 08:12:31">
</textarea>
<p>Now, the point is to index article title with comments. Here we can get associated article using &#8216;commentable&#8217; i.e. comment.commentable.</p>
<p>So, change ultrasphinx is_indexed code in comment model accordingly:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
class Comment < ActiveRecord::Base
  belongs_to :commentable, :polymorphic => true

  is_indexed :fields => :body,
            :include => [{ :association_name => 'commentable', :field => 'title', :as=> 'article_title'}]

end
</textarea>
<p>Note that we have changed associan_name to &#8216;commentable&#8217;.<br />
Next, when we reconfigure ultrasphinx using &#8221; rake ultrasphinx:bootstrap&#8221;(since we have changed db schema), it starts throwing errors:</p>
<textarea name="code" class="c" cols="50" rows="10">
** Invoke ultrasphinx:bootstrap (first_time)
** Invoke ultrasphinx:_environment (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
uninitialized constant Commentable
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:278:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:467:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:479:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/inflector.rb:283:in `constantize'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/string/inflections.rb:143:in `constantize'
/Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/associations.rb:19:in `get_association_model'
/Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/fields.rb:128:in `configure'
/Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/fields.rb:124:in `each'
/Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/fields.rb:124:in `configure'
/Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/fields.rb:101:in `each'
/Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/fields.rb:101:in `configure'
/Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/configure.rb:32:in `load_constants'
/Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/autoload.rb:8:in `after_initialize'
/Library/Ruby/Gems/1.8/gems/rails-2.1.0/lib/initializer.rb:148:in `process'
/Library/Ruby/Gems/1.8/gems/rails-2.1.0/lib/initializer.rb:93:in `send'
/Library/Ruby/Gems/1.8/gems/rails-2.1.0/lib/initializer.rb:93:in `run'
/Users/akhilbansal/work/sti/config/environment.rb:13
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require'
/Library/Ruby/Gems/1.8/gems/rails-2.1.0/lib/tasks/misc.rake:3
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:518:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `send'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:515:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:507:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:518:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `send'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:515:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:507:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

</textarea>
<p>After spending some time on research, I was able to make it work by making some changes in comment model:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
class Comment < ActiveRecord::Base
  belongs_to :commentable, :polymorphic => true

is_indexed :fields  => :body,
           :include => [{:class_name => 'Article',  :association_sql => 'left outer join articles on articles.id = comments.commentable_id and comments.commentable_type = "Article"', :field => 'title', :as=> 'article_title'}]
end
</textarea>
<p>Lets check it on rails console:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
>> search = Ultrasphinx::Search.new(:query => 'first article', :class_name => "Comment").run.results
=> [#<Comment id: 1, body: "hello there, I am a comment", commentable_id: 1, commentable_type: "Article", created_at: "2008-08-07 08:14:29", updated_at: "2008-08-07 08:14:29">, #<Comment id: 2, body: "hi there, this is second comment", commentable_id: 1, commentable_type: "Article", created_at: "2008-08-07 08:15:34", updated_at: "2008-08-07 08:15:34">]

</textarea>
<p>In such cases we need to define class_name and association_sql in is_indexed statement instead of association_name.</p>
<p>Hope it helps&#8230;
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2008/08/07/when-ultrasphinx-is-used-with-polymorphic-associations/feed/</wfw:commentRss>
		</item>
		<item>
		<title>When Ultrasphinx is used with STI&#8230;</title>
		<link>http://webonrails.com/2008/07/31/when-ultrasphinx-is-used-with-sti/</link>
		<comments>http://webonrails.com/2008/07/31/when-ultrasphinx-is-used-with-sti/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 14:06:38 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>RubyonRails</category>

		<category>ultrasphinx</category>

		<category>STI</category>

		<guid isPermaLink="false">http://webonrails.com/2008/07/31/when-ultrasphinx-is-used-with-sti/</guid>
		<description><![CDATA[Hi Guys, it has been a long time since I last posted. I had worked on several things since then, and have couple of posts pending/draft. One of those posts is related to Ultrasphinx, when it is used with STI models.
For those who are new to Ultrasphinx: Ultrasphinx is a rails plugin and client to [...]]]></description>
			<content:encoded><![CDATA[<p>Hi Guys, it has been a long time since I last posted. I had worked on several things since then, and have couple of posts pending/draft. One of those posts is related to Ultrasphinx, when it is used with STI models.</p>
<p>For those who are new to Ultrasphinx: Ultrasphinx is a rails plugin and client to the Sphinx(full text search engine) written by Evan Weaver. More about <a href = "http://blog.evanweaver.com/files/doc/fauna/ultrasphinx/files/README.html" target = '_blank'>Ultrasphinx here.</a></p>
<p>Lets get into the situation. Consider a STI case where we are using ultrasphinx to index several fields:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
class Post < ActiveRecord::Base

end
</textarea>
<textarea name="code" class="ruby" cols="50" rows="10">
class Article < Post
  is_indexed :fields => [:title, :body]
end
</textarea>
<textarea name="code" class="ruby" cols="50" rows="10">
class Story < Post
  is_indexed :fields => [:title, :body]
end
</textarea>
<p>Now assume we have following data in posts table:<br />
<img id="image116" src="http://webonrails.com/wp-content/uploads/2008/07/picture-4.png" alt="picture-4.png" /><br />
and now in application root:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
rake ultrasphinx:configure
rake ultrasphinx:index
rake ultrasphinx:daemon:start
</textarea>
<p>By this point we have created sphinx configuration file, indexed all records from ultrasphinx models and started sphinx search daemon.</p>
<p>Now open script/console and create and fire a query to find some articles:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
>> search = Ultrasphinx::Search.new(:query => "second article", :class_names => 'Article')
=> #<Ultrasphinx::Search:0x2105bec @subtotals={}, @response={}, @facets={}, @options={"indexes"=>"main", "class_names"=>["Article"], "sort_by"=>nil, "parsed_query"=>"second article", "sort_mode"=>"relevance", "weights"=>{}, "filters"=>{}, "per_page"=>20, "query"=>"second article", "page"=>1, "facets"=>[], "location"=>{"units"=>"radians", "long_attribute_name"=>"lng", "lat_attribute_name"=>"lat"}}, @results=[]>
>> search.run
ActiveRecord::RecordNotFound: Couldn't find Article with ID=5
	from /Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/search/internals.rb:308:in `reify_results'
	from /Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/search/internals.rb:286:in `each'
	from /Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/search/internals.rb:286:in `reify_results'
	from /Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/search.rb:357:in `run'
	from /Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/search/internals.rb:352:in `perform_action_with_retries'
	from /Users/akhilbansal/work/sti/vendor/plugins/ultrasphinx/lib/ultrasphinx/search.rb:337:in `run'
	from (irb):3
</textarea>
<p>Here when you run the query you get an exception, because it is trying to find an article with id 5, which actually a story type not article. So why it is trying to find such article?</p>
<p>Now have a look into config/ultrasphinx/development.conf file. Under section &#8220;source articles_main&#8221; you&#8217;ll get &#8220;SELECT (posts.id * 3 + 0) AS id, &#8216;&#8217; AS article_title, posts.body AS body, &#8216;Article&#8217; AS class, 0 AS class_id, posts.title AS title FROM posts WHERE posts.id >= $start AND posts.id <= $end GROUP BY posts.id" Which is a SQL to get record to index.</p>
<p>If you check it carefully you'll findout that it should select all articles record to index but unfortunately it is selecting all records from table and considering them as articles. To fix it you need to modify this query and add "posts.type = 'Article'" in where condition. So the query should be "SELECT (posts.id * 3 + 0) AS id, '' AS article_title, posts.body AS body, 'Article' AS class, 0 AS class_id, posts.title AS title FROM posts WHERE (posts.type = 'Article') and posts.id >= $start AND posts.id <= $end GROUP BY posts.id" </p>
<p>But still there is a problem. If you do this manually you have to do it again and again whenever you issue "rake ultrasphinx:configure" because this configuration file will be overwritten.</p>
<p>Better option is to add conditions in models as is_indexed options like:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
class Article < Post
  is_indexed :fields => [:title, :body], :conditions => "posts.type = 'Article'"
end
</textarea>
<p>and it worked fine.</p>
<p><a href = 'http://fromdelhi.com' target = '_blank'>Manik</a> gave me an idea to write a patch for ultrasphinx to add such conditions automatically in case of STI. So may be another post related to ultrasphinx will be soon ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2008/07/31/when-ultrasphinx-is-used-with-sti/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Git Error: trailing whitespace, indent SP followed by a TAB, unresolved merge conflict</title>
		<link>http://webonrails.com/2008/04/23/git-error-trailing-whitespace-indent-sp-followed-by-a-tab-unresolved-merge-conflict/</link>
		<comments>http://webonrails.com/2008/04/23/git-error-trailing-whitespace-indent-sp-followed-by-a-tab-unresolved-merge-conflict/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 18:19:34 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>RubyonRails</category>

		<category>Tools</category>

		<category>Git</category>

		<category>VCS</category>

		<category>SCM</category>

		<category>pre-commit</category>

		<guid isPermaLink="false">http://webonrails.com/2008/04/23/git-error-trailing-whitespace-indent-sp-followed-by-a-tab-unresolved-merge-conflict/</guid>
		<description><![CDATA[I have been using Git from last few days, and faced following errors while committing:
1) Trailing whitespace
2) Indent SP followed by a TAB
3) Unresolved merge conflict
The first error &#8220;Trailing whitespace&#8221; is because of carriage-return/line-feed(windows style line feed/end). To resolve this problem comment following lines(58-60) in .git/hooks/pre-commit file:

  if (/\s$/) {
    bad_line("trailing [...]]]></description>
			<content:encoded><![CDATA[<p>I have been using <a href="http://git.or.cz/" target ="_blank">Git</a> from last few days, and faced following errors while committing:</p>
<p>1) Trailing whitespace<br />
2) Indent SP followed by a TAB<br />
3) Unresolved merge conflict</p>
<p>The first error <strong>&#8220;Trailing whitespace&#8221;</strong> is because of carriage-return/line-feed(windows style line feed/end). To resolve this problem comment following <strong>lines(58-60) in .git/hooks/pre-commit file</strong>:</p>
<textarea name="code" class="c" cols="50" rows="10">
  if (/\s$/) {
    bad_line("trailing whitespace", $_);
 }
</textarea>
<p>The second one <strong>&#8220;Indent SP followed by a TAB&#8221;</strong> is because of leading spaces/tabs. To resolve this problem comment following <strong>lines(61-63) in .git/hooks/pre-commit file</strong>:</p>
<textarea name="code" class="c" cols="50" rows="10">
  if (/^\s*   /) {
    bad_line("indent SP followed by a TAB", $_);
  }
</textarea>
<p>The third one <strong>&#8220;Unresolved merge conflict&#8221;</strong> is because of seven or more successive  occurrence of = or < or > characters. Major chances of having seven = character in README or doc files. To resolve this problem replace following <strong>line(64) in .git/hooks/pre-commit file</strong>:</p>
<textarea name="code" class="c" cols="50" rows="10">
  if (/^(?:[<>=]){7}/) {
</textarea>
<p>by </p>
<textarea name="code" class="c" cols="50" rows="10">
  if (/^(?:[<>=]){7}$/) {
</textarea>
<p>These tricks worked for me, I hope it could help you.
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2008/04/23/git-error-trailing-whitespace-indent-sp-followed-by-a-tab-unresolved-merge-conflict/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rails Plugin Annotate Models For Spec And Spec Fixtures</title>
		<link>http://webonrails.com/2008/04/23/rails-plugin-annotate-models-for-spec-and-spec-fixtures/</link>
		<comments>http://webonrails.com/2008/04/23/rails-plugin-annotate-models-for-spec-and-spec-fixtures/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 11:18:14 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>Rails Plugins</category>

		<category>Ruby</category>

		<category>RubyonRails</category>

		<category>Subversion</category>

		<category>Tools</category>

		<category>Git</category>

		<category>VCS</category>

		<category>svn</category>

		<category>annotate_models</category>

		<category>patch</category>

		<guid isPermaLink="false">http://webonrails.com/2008/04/23/rails-plugin-annotate-models-for-spec-and-spec-fixtures/</guid>
		<description><![CDATA[I have been using &#8220;Annotate Models&#8221; rails plugin written by Dave Thomas since I found it around one and half year ago. It really helps while writing fixtures. But if you use RSpec you might miss schema info at the top of your rspec fixture file as I do. So, today I modify the plugin [...]]]></description>
			<content:encoded><![CDATA[<p>I have been using &#8220;Annotate Models&#8221; rails plugin written by Dave Thomas since I found it around one and half year ago. It really helps while writing fixtures. But if you use RSpec you might miss schema info at the top of your rspec fixture file as I do. So, today I modify the plugin file so that it prepends schema info to spec file and fixture file. Below are the links of patch file:</p>
<p><a href="http://webonrails.com/wp-content/plugins/wp-downloadMonitor/download.php?id=9" title="Version 0.1 downloaded 204 times" >svn patch to add schema info to spec file and spec fixture file</a><br />
<a href="http://webonrails.com/wp-content/plugins/wp-downloadMonitor/download.php?id=10" title="Version 0.1 downloaded 191 times" >git patch to add schema info to spec file and spec fixture file</a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2008/04/23/rails-plugin-annotate-models-for-spec-and-spec-fixtures/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Git - Fast Version Control System</title>
		<link>http://webonrails.com/2008/02/15/git-fast-version-control-system/</link>
		<comments>http://webonrails.com/2008/02/15/git-fast-version-control-system/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 19:11:01 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>Subversion</category>

		<category>Technology</category>

		<category>Tools</category>

		<category>Git</category>

		<category>VCS</category>

		<category>svn</category>

		<category>SCM</category>

		<guid isPermaLink="false">http://webonrails.com/2008/02/15/git-fast-version-control-system/</guid>
		<description><![CDATA[Git is getting popular in Rails community these days, as there were being many changes in rails to support Git.
Git is a open sourse fast version controller system. It was originally designed by Linus Torvalds to handle large projects. It was inspired by Monotone &#038; BitKeeper. It is a distributed version controlling system. It gives [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://git.or.cz/">Git</a> is getting popular in Rails community these days, as there were being many <a href="http://dev.rubyonrails.org/changeset/8772">changes</a> in rails to support Git.<br />
Git is a open sourse fast version controller system. It was originally designed by Linus Torvalds to handle large projects. It was inspired by Monotone &#038; BitKeeper. It is a distributed version controlling system. It gives you ability to commit, traverse into history while being offline. Actually every working copy of Git is a full-fledged repository. It has no central server like <a href="http://subversion.tigris.org/">SVN</a>. One can share his working-copy/repository by using various protocols like ssh, http, ftp etc. One thing I like about Git over SVN is that the size of Git&#8217;s repository, which is smaller compared to SVN.</p>
<p>I gave an introductory presentation in <a href="http://vinsol.com/">VinSol</a>. I am sharing it with you, this is not very explanatory as I focused on speech more. Please share your views.</p>
<div style="width:425px;text-align:left" id="__ss_354888"><object style="margin:0px" width="425" height="355">
<param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=git1-1208284093507575-8"/>
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=git1-1208284093507575-8" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"><a href="http://www.slideshare.net/?src=embed"><img src="http://static.slideshare.net/swf/logo_embd.png" style="border:0px none;margin-bottom:-5px" alt="SlideShare"/></a> | <a href="http://www.slideshare.net/bansalakhil/git-fast-version-control-system-354888?src=embed" title="View 'Git- Fast version control system' on SlideShare">View</a> | <a href="http://www.slideshare.net/upload?src=embed">Upload your own</a></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2008/02/15/git-fast-version-control-system/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Migration: Adding/Removing columns are now much easier</title>
		<link>http://webonrails.com/2008/01/23/migration_adding_removing_columns_are_now_much_easier/</link>
		<comments>http://webonrails.com/2008/01/23/migration_adding_removing_columns_are_now_much_easier/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 17:24:54 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>Ruby</category>

		<category>RubyonRails</category>

		<category>Technology</category>

		<category>Web Development</category>

		<category>migration</category>

		<guid isPermaLink="false">http://webonrails.com/2008/01/23/migration_adding_removing_columns_are_now_much_easier/</guid>
		<description><![CDATA[You may have noticed by now, that in Rails 2.0 changeset 7422, you can specify columns you want to add/remove in your migration by passing attribute:type pairs to the migration generator. 
For example, lets assume that we need to add a column &#8216;role&#8217; in users table(User model). In this case generate a migration like:

script/generate migration [...]]]></description>
			<content:encoded><![CDATA[<p>You may have noticed by now, that in Rails 2.0 <a href="http://dev.rubyonrails.org/changeset/7422">changeset 7422</a>, you can specify columns you want to add/remove in your migration by passing <strong>attribute:type</strong> pairs to the migration generator. </p>
<p>For example, lets assume that we need to add a column &#8216;role&#8217; in users table(User model). In this case generate a migration like:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
script/generate migration AddRoleToUser role:string
</textarea>
<p>Output:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
class AddRoleToUser < ActiveRecord::Migration
  def self.up
    add_column :users, :role, :string
  end

  def self.down
    remove_column :users, :role
  end
end
</textarea>
<p>Here <strong>Add</strong>Role<strong><em>To</em></strong><strong>User</strong> plays the main role. &#8216;Add&#8217; specifies the we want to add column(s) and &#8216;User&#8217; separated by &#8216;To&#8217; specifies the table.</p>
<p>Similarly, if we need to remove a column &#8216;role&#8217; :</p>
<textarea name="code" class="ruby" cols="50" rows="10">
 script/generate migration RemoveRoleFromUser role:string
</textarea>
<p>Output:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
class RemoveRoleFromUser < ActiveRecord::Migration
  def self.up
    remove_column :users, :role
  end

  def self.down
    add_column :users, :role, :string
  end
end
</textarea>
<p>Here <strong>Remove</strong>Role<strong><em>From</em></strong><strong>User</strong> plays the main role. &#8216;Remove&#8217; specifies the we want to remove column(s) and &#8216;User&#8217; separated by &#8216;From&#8217; specifies the table.</p>
<p>Isn&#8217;t it cool?
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2008/01/23/migration_adding_removing_columns_are_now_much_easier/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ajax based online ruby API documentation</title>
		<link>http://webonrails.com/2008/01/14/ajax-based-online-ruby-api-documentation/</link>
		<comments>http://webonrails.com/2008/01/14/ajax-based-online-ruby-api-documentation/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 18:10:07 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Ajax</category>

		<category>Ruby</category>

		<guid isPermaLink="false">http://webonrails.com/2008/01/14/ajax-based-online-ruby-api-documentation/</guid>
		<description><![CDATA[http://www.rubybrain.com/

]]></description>
			<content:encoded><![CDATA[<p>http://www.rubybrain.com/
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2008/01/14/ajax-based-online-ruby-api-documentation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ruby Script for SVN commit notification with log message, list of updated files and readable colored SVN Diff</title>
		<link>http://webonrails.com/2008/01/14/ruby-script-for-svn-commit-notification-with-log-message-list-of-updated-files-and-readable-colored-svn-diff/</link>
		<comments>http://webonrails.com/2008/01/14/ruby-script-for-svn-commit-notification-with-log-message-list-of-updated-files-and-readable-colored-svn-diff/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 14:17:16 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>Ruby</category>

		<category>RubyonRails</category>

		<category>Subversion</category>

		<category>Technology</category>

		<category>Web Development</category>

		<category>Tools</category>

		<category>notification</category>

		<guid isPermaLink="false">http://webonrails.com/2008/01/14/ruby-script-for-svn-commit-notification-with-log-message-list-of-updated-files-and-readable-colored-svn-diff/</guid>
		<description><![CDATA[Some days ago I wrote a post about &#8220;SVN commit notification&#8221; which uses a perl script for sending commit notification with svn diff by mail. In this mail you can find svn diff from the last committed revision. I used to love this mail, soon I realized that it is a bit ugly and difficult [...]]]></description>
			<content:encoded><![CDATA[<p>Some days ago I wrote a post about &#8220;<a href="http://webonrails.com/2007/07/12/get-svn-commit-notification-right-into-your-inbox-by-using-svn-hook-post-commit/">SVN commit notification</a>&#8221; which uses a perl script for sending commit notification with svn diff by mail. In this mail you can find svn diff from the last committed revision. I used to love this mail, soon I realized that it is a bit ugly and difficult to read. Also there were some important information missing.  Like the name of user committing the code, the log message etc&#8230; </p>
<p>And then I started writing my own ruby script for same purpose but with some addition and modification. <a href="http://webonrails.com/wp-content/plugins/wp-downloadMonitor/download.php?id=8" title="Version 0.2 downloaded 418 times" >Commit notification script</a> is that script, you can download and configure it with your SVN post commit hook as follows.</p>
<p>Add following line at the bottom of your post-commit file:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
/usr/bin/ruby /var/www/repositories/project/hooks/commit-email.rb "$1"  "$2"
</textarea>
<p>* Please remember to change the path of you commit-email ruby script.</p>
<p>Now open commit-email ruby file and modify the following section according to your requirement:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
# You can edit below

# Subject prefix
sub = "[test_project@vinsol]"  # A project 'test_project' is maitained at vinsol

#list of users who will recieve commit notification
recipients = ["bansalakhil30.10@gmail.com", "akhil@vinsol.com"]

# email which will appear in from email field
from_user = "svn-notify@somedomain.com"

# your smtp settings here
ActionMailer::Base.smtp_settings = { :address => 'localhost', :port => 25, :domain => 'domain.com'}

# Do not edit below this line
</textarea>
<p>You are done with that, now onwards whenever someone commits the code, you&#8217;ll get the commit notification mail like:</p>
<p><a class="imagelink" href="http://webonrails.com/wp-content/uploads/2008/01/commit-email-preview.png" title="Commit Email Preview"><img id="image104"  width = 100% src="http://webonrails.com/wp-content/uploads/2008/01/commit-email-preview.png" alt="Commit Email Preview" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2008/01/14/ruby-script-for-svn-commit-notification-with-log-message-list-of-updated-files-and-readable-colored-svn-diff/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Presented at BarCampDelhi3</title>
		<link>http://webonrails.com/2007/12/10/presented-in-barcampdelhi3/</link>
		<comments>http://webonrails.com/2007/12/10/presented-in-barcampdelhi3/#comments</comments>
		<pubDate>Mon, 10 Dec 2007 07:57:33 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>RubyonRails</category>

		<category>Barcamp</category>

		<category>hosting</category>

		<category>deployment</category>

		<category>Delhi</category>

		<category>Event</category>

		<category>EC2</category>

		<guid isPermaLink="false">http://webonrails.com/2007/12/10/presented-in-barcampdelhi3/</guid>
		<description><![CDATA[Yesterday, I attended third barcamp in delhi. I presented a session &#8220;Deploying rails application in EC2&#8243;.  It was an amazing experience. We talked about EC2 and I had given a demo &#8220;How to deploy rails application on EC2&#8243;.
I personally didn&#8217;t like some sessions. There were people from some company and after every 2 mins [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I attended<a href="http://www.barcamp.org/BarCampDelhi3"> third barcamp in delhi</a>. I presented a session &#8220;Deploying rails application in EC2&#8243;.  It was an amazing experience. We talked about EC2 and I had given a demo &#8220;How to deploy rails application on EC2&#8243;.</p>
<p>I personally didn&#8217;t like some sessions. There were people from some company and after every 2 mins they were saying &#8220;we are the best&#8221;. I think this should not happen in barcamp. As far as I know about barcamp, it is for sharing your experiences, talking about new technology, but not for promoting your company.</p>
<p>I think that, at BarCamp there should be sessions on new things, not on the things that are popular and have similar other services.</p>
<p>There was a very good session by  Jinesh Varia on Amazon Cloud Computing. He included Amazon&#8217;s simple storage system, and  Amazon&#8217;s cloud computing(Ec2) in his presentation. He also helped me in answering people while the demo. He gave me a hint that very soon there will a news from Amazon that will surprise us. </p>
<p>I have uploaded my presentation slides on Slideshare.net:</p>
<div style="width:425px;text-align:left" id="__ss_197972"><object style="margin:0px" width="425" height="355">
<param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=deploying-rails-app-on-ec2-1197272291134652-3"/>
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=deploying-rails-app-on-ec2-1197272291134652-3" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"><a href="http://www.slideshare.net/?src=embed"><img src="http://static.slideshare.net/swf/logo_embd.png" style="border:0px none;margin-bottom:-5px" alt="SlideShare"/></a> | <a href="http://www.slideshare.net/bansalakhil/deploying-rails-app-on-ec2" title="View 'Deploying Rails App On Ec2' on SlideShare">View</a> | <a href="http://www.slideshare.net/upload">Upload your own</a></div>
</div>
<p>Thanks to <a href="http://impetus.com">Impetus</a> Noida for Hosting Barcamp for second time and <a href="http://www.opera.com/">Opera</a> for Beer.
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2007/12/10/presented-in-barcampdelhi3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Third Delhi BarCamp</title>
		<link>http://webonrails.com/2007/11/21/third-delhi-barcamp/</link>
		<comments>http://webonrails.com/2007/11/21/third-delhi-barcamp/#comments</comments>
		<pubDate>Wed, 21 Nov 2007 08:27:04 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>Barcamp</category>

		<category>Delhi</category>

		<category>Event</category>

		<guid isPermaLink="false">http://webonrails.com/2007/11/21/third-delhi-barcamp/</guid>
		<description><![CDATA[I have a great news for you guys. We are planning Third BarCamp on Saturday, 8 December 2007, in Delhi.
Venue is not finalize yet, We have some options and shortlisting the final one.
We are also waiting for someone to take the sponsorship ;-)
Some people have proposed their sessions, I am proposing two with Manik. List [...]]]></description>
			<content:encoded><![CDATA[<p>I have a great news for you guys. We are planning Third BarCamp on Saturday, 8 December 2007, in Delhi.<br />
Venue is not finalize yet, We have some options and shortlisting the final one.<br />
We are also waiting for someone to take the sponsorship ;-)<br />
Some people have proposed their sessions, I am proposing two with <a href="http://fromdelhi.com">Manik</a>. List of sessions(as of now):</p>
<ul>
<strong>    * Deploying Rails app on EC2 (Manik Juneja and Akhil Bansal)<br />
    * Comparison of various Rails Hosting services. (Manik Juneja and Akhil Bansal)<br />
</strong>    * Using Jmeter for Stress Testing your webapp<br />
    * Desi Social Networking - Visual web ( Swagat Sen )<br />
    * Everyday Productivity with Windows Live Tools (Abhishek Kant)<br />
    * Gurugeeks - A call out for Web Geeks (Navjot Pawera)<br />
    * Web Semantics and Accessibility (Navjot Pawera)
</ul>
<p>If you are planning to Attend/Present something you or want to help us in any way  please visit  <a href="http://barcamp.org/BarCampDelhi3">http://barcamp.org/BarCampDelhi3</a> and add you name in appropriate section.</p>
<p>So see you in the camp ;-)
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2007/11/21/third-delhi-barcamp/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Two best online API/Rails API</title>
		<link>http://webonrails.com/2007/11/05/two-best-online-api-rails-api/</link>
		<comments>http://webonrails.com/2007/11/05/two-best-online-api-rails-api/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 08:08:17 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Ajax</category>

		<category>Rails</category>

		<category>Ruby</category>

		<category>RubyonRails</category>

		<category>API</category>

		<guid isPermaLink="false">http://webonrails.com/2007/11/05/two-best-online-apirails-api/</guid>
		<description><![CDATA[Today I found two best API sites. One is http://www.gotapi.com.
This site provides APIs of almost all languages.
The other API site which is only focused on Rails is http://www.railsbrain.com/. I like this most. You can also download this API. It is AJAX based fast, useful.

]]></description>
			<content:encoded><![CDATA[<p>Today I found two best API sites. One is <a href="http://www.gotapi.com">http://www.gotapi.com</a>.<br />
This site provides APIs of almost all languages.</p>
<p>The other API site which is only focused on Rails is <a href="http://www.railsbrain.com/">http://www.railsbrain.com/</a>. I like this most. You can also download this API. It is AJAX based fast, useful.
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2007/11/05/two-best-online-api-rails-api/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Single Table Inheritance validates_uniqueness_of Problem</title>
		<link>http://webonrails.com/2007/10/26/single-table-inheritance-validates_uniqueness_of-problem/</link>
		<comments>http://webonrails.com/2007/10/26/single-table-inheritance-validates_uniqueness_of-problem/#comments</comments>
		<pubDate>Fri, 26 Oct 2007 07:45:02 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>Ruby</category>

		<category>RubyonRails</category>

		<category>Technology</category>

		<category>Web Development</category>

		<guid isPermaLink="false">http://webonrails.com/2007/10/26/single-table-inheritance-validates_uniqueness_of-problem/</guid>
		<description><![CDATA[Consider a case of STI where:

class User < ActiveRecord::Base
  validates_uniqueness_of :name
end

class Customer < User

end

class Manager < User

end

Now try following at console:

User.create(:name => "Akhil Bansal")
Manager.create(:name => "Akhil Bansal")
Customer.create(:name => "Akhil Bansal")

This will let you create three records in users table with same name, validates_uniqueness_of written in User class has no effect on it. validates_uniqueness_of automatically [...]]]></description>
			<content:encoded><![CDATA[<p>Consider a case of STI where:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
class User < ActiveRecord::Base
  validates_uniqueness_of :name
end

class Customer < User

end

class Manager < User

end
</textarea>
<p>Now try following at console:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
User.create(:name => "Akhil Bansal")
Manager.create(:name => "Akhil Bansal")
Customer.create(:name => "Akhil Bansal")
</textarea>
<p>This will let you create three records in users table with same name, validates_uniqueness_of written in User class has no effect on it. validates_uniqueness_of automatically scoped with class names, that means it will not let you create two managers with same name or two customers with same name  or two users with same name. </p>
<p>If you want uniqueness of an attribute in overall table, put the following code in some file in your lib dir and require that file in environment:</p>
<textarea name="code" class="ruby" cols="50" rows="10">
module ActiveRecord
  module Validations
    module ClassMethods
      # Intended for use with STI tables, helps ignore the type field
      def validates_overall_uniqueness_of(*attr_names)
        configuration = { :message => "has already been taken" }
        configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
        validates_each(attr_names, configuration) do |record, attr_name, value|
          records = self.find(:all, :conditions=> ["#{attr_name} = ?", value])
          record.errors.add(attr_name, configuration[:message]) if records.size > 0 and records[0].id != record.id
        end
      end
    end
  end
end
</textarea>
<p>And then use validates_overall_uniqueness_of instead of validates_uniqueness_of.
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2007/10/26/single-table-inheritance-validates_uniqueness_of-problem/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Running Rails Application on https with pound</title>
		<link>http://webonrails.com/2007/09/13/running-rails-application-on-https-with-pound/</link>
		<comments>http://webonrails.com/2007/09/13/running-rails-application-on-https-with-pound/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 13:58:56 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>RubyonRails</category>

		<category>Technology</category>

		<category>hosting</category>

		<category>pound</category>

		<category>mongrel_cluster</category>

		<category>deployment</category>

		<category>https</category>

		<guid isPermaLink="false">http://webonrails.com/2007/09/13/running-rails-application-on-https-with-pound/</guid>
		<description><![CDATA[Hours ago, I posted about, &#8220;How to deploy rails application with pound as a Balancer&#8221;.
Lets run rails application on https with pound. For that your machine should have:
* Pound installed with ssl support
* Pound and mongrels running
Now, First of all we need a ssl certificate, that can be generate by issuing &#8220;openssl req -x509 -newkey [...]]]></description>
			<content:encoded><![CDATA[<p>Hours ago, I posted about, <a href="http://webonrails.com/2007/09/13/deploying-rails-application-with-pound-as-a-balancer/" target = "_blank">&#8220;How to deploy rails application with pound as a Balancer&#8221;</a>.</p>
<p>Lets run rails application on https with pound. For that your machine should have:</p>
<p>* Pound installed with ssl support<br />
* Pound and mongrels running</p>
<p>Now, First of all we need a ssl certificate, that can be generate by issuing <strong>&#8220;openssl req -x509 -newkey rsa:1024 -keyout mydomain.pem  -out mydomain.pem -days 365 -nodes&#8221;</strong> . Give all the information it asks. Now copy mydomain.pem to /etc/pound/ directory(I am assuming that your pound.cfg file resides in /etc/pound/). Now put the following code in pound configuration file(/etc/pound/pound.cfg):</p>
<textarea name="code" class="c++" cols="50" rows="10">
ListenHTTPS
  Address 0.0.0.0
  Port    443
  Cert    "/etc/pound/mydomain.pem" 
  # pass along https hint
  AddHeader "X-Forwarded-Proto: https" 
  HeadRemove "X-Forwarded-Proto" 

Service
    URL "/(images|stylesheets|javascripts)/"
    BackEnd
        Address 127.0.0.1
        Port    8080
    End
    Session
        Type    BASIC
        TTL     300
    End

End

  Service
    BackEnd
      Address 127.0.0.1
      Port    8000
    End
    BackEnd
      Address 127.0.0.1
      Port    8001
    End
    BackEnd
      Address 127.0.0.1
      Port    8002
    End
  End
End
</textarea>
<p>I am assuming that your mongrels are running at ports 8000, 8001, 8002, apache running at 8080 and pound is listening ports 443 &#038; 80.<br />
Restart pound, and you are done. With this configuration all requests for dynamic content at port 443(https) will get redirected to mongrels and requests for static content will get redirected to apache.</p>
<p>You may want to check if the request is https or not before serving the content. That can be done by adding a before_filter (defined below) in application.rb  :</p>
<textarea name="code" class="ruby" cols="50" rows="10">
def confirm_ssl
  unless request.ssl?
    request.env["HTTPS"] = "on"
    redirect_to "/"
    return
  end
end
</textarea>
<p>By adding this method as before_filter in application.rb your application will check for https, if the request is not of type https it will redirect to an https request.
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2007/09/13/running-rails-application-on-https-with-pound/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Deploying rails application with pound as a Balancer</title>
		<link>http://webonrails.com/2007/09/13/deploying-rails-application-with-pound-as-a-balancer/</link>
		<comments>http://webonrails.com/2007/09/13/deploying-rails-application-with-pound-as-a-balancer/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 12:40:38 +0000</pubDate>
		<dc:creator>Akhil Bansal</dc:creator>
		
		<category>Rails</category>

		<category>RubyonRails</category>

		<category>Technology</category>

		<category>Web Development</category>

		<category>hosting</category>

		<category>pound</category>

		<category>mongrel_cluster</category>

		<category>deployment</category>

		<guid isPermaLink="false">http://webonrails.com/2007/09/13/deploying-rails-application-with-pound-as-a-balancer/</guid>
		<description><![CDATA[Now a days Apache + mod_proxy + mongrel_clusters, Lighttpd + Mongrel cluster and Nginx + mongrel cluster are well known for deploying rails applications. 
You can also deploy your rails application with pound(a reverse proxy, load balancer and HTTPS front-end for Web server). 
First you need to setup mongrel_clusters for your rails application by issuing [...]]]></description>
			<content:encoded><![CDATA[<p>Now a days Apache + mod_proxy + mongrel_clusters, Lighttpd + Mongrel cluster and Nginx + mongrel cluster are well known for deploying rails applications. </p>
<p>You can also deploy your rails application with <a href="http://www.apsis.ch/pound/"  target= "_blank">pound</a>(a reverse proxy, load balancer and HTTPS front-end for Web server). </p>
<p>First you need to setup mongrel_clusters for your rails application by issuing &#8221; <strong>mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N 3 -c ./</strong> &#8221; inside the rails application root directory(on client machine). This will create mongrel_cluster.yml in config directory. You can change parameters in this command, as -p 8000 specifies that mongrel instances  will start  up on port  number starting 8000, -a 127.0.0.1 specifies that mongrel instances will listen to the localhost, -N specifies the number of mongrel instances and -c specifies the rails root directory.</p>
<p>Now you need to install pound(if not installed) by issuing following commands(as root):</p>
<ul>
<li>cd /opt/src</li>
<li>wget http://www.apsis.ch/pound/Pound-2.3.2.tgz</li>
<li>tar xzpf Pound-2.1.6.tgz</li>
<li>cd Pound-2.1.6</li>
<li>./configure</li>
<li>make</li>
<li>make install</li>
</ul>
<p>This will install pound in /usr/local/sbin/pound. In order to proceed further we need to create pound.cfg(pound configuration file) in /etc/pound/pound.cfg . Below is the content of pound.cfg:</p>
<textarea name="code" class="c++" cols="50" rows="10">
                                             
User "pound"
Group "pound"

ListenHTTP
  Address 0.0.0.0
  Port 80
  Service
    BackEnd
      Address 127.0.0.1
      Port 8000
    End
    BackEnd
      Address 127.0.0.1
      Port 8001
    End
    BackEnd
      Address 127.0.0.1
      Port 8002
    End
  End
End
</textarea>
<p>Start mongrel cluster by issuing mongrel_rails cluster::start in you app root directory, start pound by /usr/local/sbin/pound -f /etc/pound/pound.cfg , now you are done. Pound is listening the port 80 and redirect all requests to mongrel instances running on 8000, 8001, 8002.</p>
<p>* Please Note that we have configured pound at port 80, if port 80 is being used by apache or any other application pound will not start. You need to stop any service using  port 80, if it is apache then stop apache, change line &#8216;Listen 80&#8242; to &#8220;Listen 8080&#8243; and start apache.</p>
<p>In a specific case, when apache is running at some port (let say 8080), you may want to use apache to serve static content of your application, in order to reduce some load from mongrels. In that case use the following:</p>
<textarea name="code" class="c++" cols="50" rows="10">
                                             
User "pound"
Group "pound"

ListenHTTP
  Address 0.0.0.0
  Port 80
  Service
      URL "/(images|stylesheets|flash|javascripts)/"
      BackEnd 
          Address 127.0.0.1
          Port    8080   
      End
      Session 
          Type    BASIC   
          TTL     300     
      End
  End
  Service
    BackEnd
      Address 127.0.0.1
      Port 8000
    End
    BackEnd
      Address 127.0.0.1
      Port 8001
    End
    BackEnd
      Address 127.0.0.1
      Port 8002
    End
  End
End
</textarea>
<p>This will redirect all requests for image, stylesheets, javascripts, flash to apache. Now we need to configure apache to serve those static content. Just add a virtualhost for that:</p>
<textarea name="code" class="c++" cols="50" rows="10">
<VirtualHost *:8080>
  ServerName example.com
  ServerAlias www.example.com
  DocumentRoot /var/www/html/example.com/public
  <Directory "/var/www/html/example.com/public" >
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>

  RewriteEngine On

  # For static files it's good to avoid hitting your mongrel process
  # so let apache knows it should serve it directly
  # for a rails application it means, files in images / stylesheets / javascripts
  RewriteRule "^/(images|stylesheets|flash|javascripts)/?(.*)" "$0" [L]

</VirtualHost>
</textarea>
<p>Its all done. All requests for dynamic content at port 80 will be redirect to mongrel running at 8000, 8001, 8001 and requests for static content will be served by apache running at port 8080.
</p>
]]></content:encoded>
			<wfw:commentRss>http://webonrails.com/2007/09/13/deploying-rails-application-with-pound-as-a-balancer/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
