<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7962756704981038195</id><updated>2024-08-28T04:48:23.132-07:00</updated><category term="ruby"/><category term="rails"/><category term="ruby module"/><category term="$"/><category term="$A"/><category term="$F"/><category term="$W"/><category term="Object in array"/><category term="Polymorphic relation"/><category term="Proc"/><category term="active record base increment and decrement"/><category term="active record decrement field"/><category term="active record increment field"/><category term="acts_as_solr"/><category term="acts_as_solr :if option"/><category term="acts_as_solr gem/plugin installtion"/><category term="acts_as_solr integration"/><category term="acts_as_solr on windows"/><category term="acts_as_solr options"/><category term="acts_as_solr reindex with :if condition"/><category term="add fav icon"/><category term="app.get"/><category term="app.post"/><category term="array collect"/><category term="assert_tag in rails"/><category term="authlogic login failed test"/><category term="authlogic login test"/><category term="authlogic rails functional"/><category term="authlogic rails test"/><category term="background job"/><category term="blocks"/><category term="console app"/><category term="defined?"/><category term="dropdown options"/><category term="dropdown selected"/><category term="exclamation mark"/><category term="exclamation mark method"/><category term="extend method"/><category term="extend module"/><category term="favicon"/><category term="find in windows"/><category term="foreach method"/><category term="friends association"/><category term="functional testing in rails"/><category term="grep command"/><category term="grep in windows"/><category term="group by month"/><category term="has_many relation"/><category term="has_many_friends"/><category term="hmbtm"/><category term="html drop down"/><category term="include module"/><category term="instance method"/><category term="instance method call using send"/><category term="integration test with ajax"/><category term="jQuery conflict"/><category term="javascript object"/><category term="jquery"/><category term="jquery with rails"/><category term="js array"/><category term="js array collect"/><category term="js array for loop"/><category term="json"/><category term="local variable"/><category term="method call"/><category term="model association"/><category term="module in ruby"/><category term="multiple inheritance"/><category term="order by field"/><category term="order by field option"/><category term="order by month and year"/><category term="order by name"/><category term="post count display"/><category term="post count plus month display"/><category term="proc.call"/><category term="prototype.js"/><category term="rails 3.1 ajax test call"/><category term="rails 3.1 integration test"/><category term="rails console"/><category term="rails defined"/><category term="rails functional test for xhr action"/><category term="rails has_many"/><category term="rails order  by"/><category term="rails prototype js"/><category term="rbw"/><category term="ruby background"/><category term="ruby defined"/><category term="ruby exclamation mark method"/><category term="ruby extend"/><category term="ruby include"/><category term="ruby keywords"/><category term="ruby process in background"/><category term="ruby send"/><category term="ruby send method"/><category term="ruby variable"/><category term="script/console"/><category term="selected index value"/><category term="sql order by"/><category term="test text field select_tag div img in rails functionals testing"/><category term="try"/><category term="update_attribute"/><category term="use of module"/><category term="watir select box"/><category term="watir text field"/><category term="xhr integration test"/><category term="yield"/><title type='text'>vadivelan ruby on rails blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Vadivelan Kuppusamy</name><uri>http://www.blogger.com/profile/01672638241124545049</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSy10yNZEoISVVnQC2vxxDCFE0gI1C_8Qcj8L9E4_VWYNEYHs1vcd7dmkplfAD_6JEjdZf4Tn1S6kS5RK-qj0Z9kFMiPopxKVEY1MBUvJ5LYPofOFkZHo3v0vfFkOcDQ/s220/vadi_k.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>29</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-6217768041416515889</id><published>2014-07-10T05:14:00.002-07:00</published><updated>2014-07-10T05:14:43.007-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="exclamation mark"/><category scheme="http://www.blogger.com/atom/ns#" term="exclamation mark method"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby exclamation mark method"/><title type='text'>Ruby exclamation mark method</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In ruby, we see the methods with name ends with ?, !

Most of us know about the use of method name ends with ?. Ex: is_public?
We are expecting the method to return result in boolean value(true/false).

In exclamatory methods, usage is something different. See the following examples,
&lt;blockquote&gt;
&lt;b&gt;a = &quot;A STRING&quot;  &lt;br/&gt;
puts a.downcase =&gt; a string &lt;br/&gt;
puts a =&gt; A String&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;

b = &quot;ANOTHER STRING&quot;  &lt;br/&gt;
puts b.downcase! =&gt; another string&lt;br/&gt;
puts b =&gt; another string&lt;br/&gt;&lt;/b&gt;
&lt;/blockquote&gt;
For no match case, gsub will return the actual string without any change in it

&lt;blockquote&gt;
&lt;b&gt;puts &quot;ruby on rails&quot;.gsub(&quot;none&quot;,&quot;--&quot;) =&gt; ruby on rails&lt;/b&gt;
&lt;/blockquote&gt;

For no match case, gsub! will return nil

&lt;blockquote&gt;
&lt;b&gt;puts &quot;ruby on rails&quot;.gsub!(&quot;none&quot;,&quot;--&quot;).inspect&lt;/b&gt;
&lt;/blockquote&gt;

People call methods ends with exclamation mark is dangerous to use/careful when using it. The reason is, in some cases it will throw exception instead of false.

Ex:
&lt;blockquote&gt;
&lt;b&gt;save =&gt; return false if save fails&lt;br/&gt;
save! =&gt; raise an exception if save fails&lt;/b&gt;
&lt;/blockquote&gt;

We have a lot of exclamation mark methods in ruby, start looking on each one with their usage and start using it.&lt;br/&gt;

Hope it helps..&lt;br/&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/6217768041416515889/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2014/07/ruby-exclamation-mark-method.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/6217768041416515889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/6217768041416515889'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2014/07/ruby-exclamation-mark-method.html' title='Ruby exclamation mark method'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-7006445983693736722</id><published>2014-07-08T00:02:00.001-07:00</published><updated>2014-07-08T00:02:13.716-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="rails"/><category scheme="http://www.blogger.com/atom/ns#" term="try"/><title type='text'>Rails try method name in object</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In rails, most cases we are using the following style of code to display name, text etc..

&lt;blockquote&gt;
&lt;b&gt;user &amp;&amp; user.name&lt;/b&gt;
&lt;/blockquote&gt;

It will go lengthier &amp; is hard to maintain, check the below one
&lt;blockquote&gt;
&lt;b&gt;user &amp;&amp; !user.comments.blank? &amp;&amp; user.comments.first.text&lt;/b&gt;
&lt;/blockquote&gt;

Avoid lengthy expressions, start using &quot;try&quot;

&lt;blockquote&gt;
&lt;b&gt;user.try(:name)&lt;/b&gt;
&lt;/blockquote&gt;

It will return user name only if user object exists.

Happy coding..
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/7006445983693736722/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2014/07/rails-try-method-name-in-object.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/7006445983693736722'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/7006445983693736722'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2014/07/rails-try-method-name-in-object.html' title='Rails try method name in object'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-4412386520602215397</id><published>2012-07-16T02:24:00.001-07:00</published><updated>2012-07-16T02:26:31.707-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="extend module"/><category scheme="http://www.blogger.com/atom/ns#" term="include module"/><category scheme="http://www.blogger.com/atom/ns#" term="module in ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby extend"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby include"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby module"/><category scheme="http://www.blogger.com/atom/ns#" term="use of module"/><title type='text'>Modules in Ruby  - an overview</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;b&gt;We can define any number of methods in a module. It simply holds all the defined methods and we can include/extend it in any class.&lt;/b&gt;
&lt;br/&gt;

&lt;b&gt;If you want to use all module methods access by an instance then include the module in that class.&lt;/b&gt;
&lt;br/&gt;
&lt;b&gt;If you want to use all module methods access by an class then extend the module in that class.&lt;/b&gt;

&lt;pre style=&quot;background: #ffffff; color: black;&quot;&gt;
module Foo
  def foo
    puts &#39;foo called!&#39;
  end
end

class Bar
  include Foo
end

Bar.new.foo # foo called!
Bar.foo # NoMethodError: undefined method ‘foo’ for Bar:Class

class Baz
  extend Foo
end

Baz.foo # foo called!
Baz.new.foo # NoMethodError: undefined method ‘foo’ for #&lt;Baz:0x1e708&gt;


Hope this helps. Happy learning &amp; coding :)
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/4412386520602215397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2012/07/modules-in-ruby-overview.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/4412386520602215397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/4412386520602215397'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2012/07/modules-in-ruby-overview.html' title='Modules in Ruby  - an overview'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-6717102123532218832</id><published>2012-02-28T02:28:00.002-08:00</published><updated>2012-02-28T02:30:36.929-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="integration test with ajax"/><category scheme="http://www.blogger.com/atom/ns#" term="rails 3.1 ajax test call"/><category scheme="http://www.blogger.com/atom/ns#" term="rails 3.1 integration test"/><category scheme="http://www.blogger.com/atom/ns#" term="rails functional test for xhr action"/><category scheme="http://www.blogger.com/atom/ns#" term="xhr integration test"/><title type='text'>Rails 3.1.0 - functional/integration test to test AJAX</title><content type='html'>Integration test with ajax achieved by means of calling xhr like below&lt;br /&gt;&lt;blockquote&gt;xhr :req_method, :path, :parameters, :headers&lt;/blockquote&gt;&lt;br /&gt;&lt;blockquote&gt;xhr :get, &#39;/users/new&#39; # new user action&lt;/blockquote&gt;&lt;br /&gt;&lt;blockquote&gt;xhr :delete, &#39;/users/20&#39; # delete user&lt;/blockquote&gt; &lt;br /&gt;In integration test, you need to specify full path to make it work.&lt;br /&gt;&lt;br /&gt;Incase of Functional test, we can simply specify the name of action.&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Vadivelan.K</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/6717102123532218832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2012/02/rails-310-functionalintegration-test-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/6717102123532218832'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/6717102123532218832'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2012/02/rails-310-functionalintegration-test-to.html' title='Rails 3.1.0 - functional/integration test to test AJAX'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-272894168622473966</id><published>2012-02-28T02:16:00.002-08:00</published><updated>2012-02-28T02:22:03.988-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="authlogic login failed test"/><category scheme="http://www.blogger.com/atom/ns#" term="authlogic login test"/><category scheme="http://www.blogger.com/atom/ns#" term="authlogic rails functional"/><category scheme="http://www.blogger.com/atom/ns#" term="authlogic rails test"/><title type='text'>Authlogic login access in rails functional test</title><content type='html'>We are shifted to use Authlogic, Devise rather than rails authorization plugin/gem. We can do Integration with detailed explanations/tutorials available for Authlogic.&lt;br /&gt;&lt;br /&gt;In Rails test (functional/integration test in particular), we are in need to test whether the user is logged-in or not.&lt;br /&gt;To start testing the user session, we need to use authlogic session. By using the following steps we can access Authlogic session in our rails test&lt;br /&gt;&lt;br /&gt;- Add the following line in your test_helper.rb&lt;br /&gt;&lt;blockquote&gt;require &quot;authlogic/test_case&quot;&lt;/blockquote&gt;&lt;br /&gt;- And add the method in your test_helper.rb&lt;br /&gt;&lt;blockquote&gt;  def user_login(user)&lt;br /&gt;UserSession.create(user ? user : nil)&lt;br /&gt;  end&lt;/blockquote&gt;&lt;br /&gt;- Then inside your functional/integration test file&lt;br /&gt;  Add this to top of all test&lt;br /&gt;&lt;blockquote&gt;  setup :activate_authlogic&lt;/blockquote&gt;&lt;br /&gt;- Logged in with any existing user&lt;br /&gt;  &lt;blockquote&gt;user_login(users(:last))&lt;/blockquote&gt;&lt;br /&gt;  You are logged in.&lt;br /&gt;- User session is accessible.&lt;br /&gt;&lt;br /&gt;Web application testing is much easier in Rails :)&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Vadivelan.K</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/272894168622473966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2012/02/authlogic-login-access-in-rails.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/272894168622473966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/272894168622473966'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2012/02/authlogic-login-access-in-rails.html' title='Authlogic login access in rails functional test'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-8053952222534725103</id><published>2012-02-28T02:04:00.001-08:00</published><updated>2013-09-05T23:36:19.982-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="background job"/><category scheme="http://www.blogger.com/atom/ns#" term="rbw"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby background"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby process in background"/><title type='text'>Run ruby script as a background process in windows</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi Ruby folks,&lt;br /&gt;
&lt;br /&gt;
I went across a scenario in need of running a ruby process in background particularly in Windows OS(in Unix based system we can use &#39;&amp;amp;&#39; to run any process/job in background).&lt;br /&gt;
&lt;br /&gt;
To run any ruby program in background, do the following&lt;br /&gt;
&lt;br /&gt;
- Take a copy of the file, which you needs to run.&lt;br /&gt;
- Save the file as .rbw extension.&lt;br /&gt;
- Use the command &lt;br /&gt;
&lt;blockquote&gt;
start &quot;Your job description&quot; ruby D:\Ruby\Jobs\particular_job.rbw&lt;/blockquote&gt;
&lt;br /&gt;
- Once it started running, You got a new console window with the given message on top and process status in console.&lt;br /&gt;
&lt;br /&gt;
Cheers,&lt;br /&gt;
Vadivelan.K

&lt;/div&gt;
&lt;!-- GoStats JavaScript Based Code --&gt;
&lt;script src=&quot;http://gostats.com/js/counter.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;_gos=&#39;c4.gostats.com&#39;;_goa=382337;
_got=5;_goi=1;_gol=&#39;See web page stats about your site with minimal effort.&#39;;_GoStatsRun();&lt;/script&gt;
&lt;noscript&gt;&lt;a target=&quot;_blank&quot; title=&quot;See web page stats about your site with minimal effort.&quot; 
href=&quot;http://gostats.com&quot;&gt;&lt;img alt=&quot;See web page stats about your site with minimal effort.&quot; 
src=&quot;http://c4.gostats.com/bin/count/a_382337/t_5/i_1/counter.png&quot; 
style=&quot;border-width:0&quot; /&gt;&lt;/a&gt;&lt;/noscript&gt;
&lt;!-- End GoStats JavaScript Based Code --&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/8053952222534725103/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2012/02/run-ruby-script-as-background-process.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/8053952222534725103'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/8053952222534725103'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2012/02/run-ruby-script-as-background-process.html' title='Run ruby script as a background process in windows'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-8429622821822882528</id><published>2011-10-20T02:26:00.000-07:00</published><updated>2011-10-20T02:59:49.210-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="acts_as_solr"/><category scheme="http://www.blogger.com/atom/ns#" term="acts_as_solr :if option"/><category scheme="http://www.blogger.com/atom/ns#" term="acts_as_solr gem/plugin installtion"/><category scheme="http://www.blogger.com/atom/ns#" term="acts_as_solr integration"/><category scheme="http://www.blogger.com/atom/ns#" term="acts_as_solr on windows"/><category scheme="http://www.blogger.com/atom/ns#" term="acts_as_solr options"/><category scheme="http://www.blogger.com/atom/ns#" term="acts_as_solr reindex with :if condition"/><title type='text'>Solr</title><content type='html'>Integrating SOLR search into our application. “acts_as_solr” is the name of the plugin(also available as gem).&lt;br /&gt;Install plugin:&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;script&lt;span style=&#39;color:#808030; &#39;&gt;/&lt;/span&gt;plugin install git:&lt;span style=&#39;color:#808030; &#39;&gt;/&lt;/span&gt;&lt;span style=&#39;color:#808030; &#39;&gt;/&lt;/span&gt;github&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;com&lt;span style=&#39;color:#808030; &#39;&gt;/&lt;/span&gt;mattmatt&lt;span style=&#39;color:#808030; &#39;&gt;/&lt;/span&gt;acts_as_solr&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;git&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Install gem:&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;gem install acts_as_solr&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Add the below line into your application&#39;s configuration file&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;config&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;gem &lt;span style=&#39;color:#0000e6; &#39;&gt;&quot;acts_as_solr&quot;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Add this at the end of your Rakefile(only for using gem)&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;&lt;span style=&#39;color:#400000; &#39;&gt;require&lt;/span&gt; &lt;span style=&#39;color:#0000e6; &#39;&gt;&#39;aas_tasks&#39;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;After installing gem/plugin, following rake tasks are available to use&lt;br /&gt;rake solr:destroy_index                              # Remove Solr index&lt;br /&gt;rake solr:reindex                                    # Reindexes data for all ac&lt;br /&gt;ts_as_solr models.&lt;br /&gt;rake solr:start                                      # Starts Solr.&lt;br /&gt;rake solr:stop                                       # Stops Solr.&lt;br /&gt;We can start, stop, reindex, destroy index by using the mentioned rake tasks.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Add the following rake task inside the solr rake file(gems/acts_as_solr/lib/tasks/solr.rake), to start solr in Windows environment.&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;desc &lt;span style=&#39;color:#0000e6; &#39;&gt;&quot;Starts Solr. on windows . Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.&quot;&lt;/span&gt;&lt;br /&gt;  task :start_win &lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;do&lt;/span&gt;&lt;br /&gt;    &lt;span style=&#39;color:#400000; &#39;&gt;require&lt;/span&gt; &lt;span style=&#39;color:#0000e6; &#39;&gt;&quot;#{File.dirname(__FILE__)}/../../config/solr_environment.rb&quot;&lt;/span&gt;&lt;br /&gt;    &lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;begin&lt;/span&gt;&lt;br /&gt;      n &lt;span style=&#39;color:#808030; &#39;&gt;=&lt;/span&gt; Net::HTTP&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;&lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;new&lt;/span&gt;&lt;span style=&#39;color:#808030; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#0000e6; &#39;&gt;&#39;localhost&#39;&lt;/span&gt;, SOLR_PORT&lt;span style=&#39;color:#808030; &#39;&gt;)&lt;/span&gt;&lt;br /&gt;      n&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;request_head&lt;span style=&#39;color:#808030; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#0000e6; &#39;&gt;&#39;/&#39;&lt;/span&gt;&lt;span style=&#39;color:#808030; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;value&lt;br /&gt;&lt;br /&gt;    &lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;rescue&lt;/span&gt; Net::HTTPServerException &lt;span style=&#39;color:#696969; &#39;&gt;#responding&lt;/span&gt;&lt;br /&gt;      &lt;span style=&#39;color:#400000; &#39;&gt;puts&lt;/span&gt; &lt;span style=&#39;color:#0000e6; &#39;&gt;&quot;Port #{SOLR_PORT} in use&quot;&lt;/span&gt; &lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;and&lt;/span&gt; &lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;return&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;rescue&lt;/span&gt; Errno::ECONNREFUSED &lt;span style=&#39;color:#696969; &#39;&gt;#not responding&lt;/span&gt;&lt;br /&gt;      Dir&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;chdir&lt;span style=&#39;color:#808030; &#39;&gt;(&lt;/span&gt;SOLR_PATH&lt;span style=&#39;color:#808030; &#39;&gt;)&lt;/span&gt; &lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;do&lt;/span&gt;&lt;br /&gt;        &lt;span style=&#39;color:#400000; &#39;&gt;exec&lt;/span&gt; &lt;span style=&#39;color:#0000e6; &#39;&gt;&quot;java -Dsolr.data.dir=solr/data/#{ENV[&#39;RAILS_ENV&#39;]} -Djetty.port=#{SOLR_PORT} -jar start.jar&quot;&lt;/span&gt;&lt;br /&gt;        &lt;span style=&#39;color:#400000; &#39;&gt;sleep&lt;/span&gt;&lt;span style=&#39;color:#808030; &#39;&gt;(&lt;/span&gt;&lt;span style=&#39;color:#008c00; &#39;&gt;5&lt;/span&gt;&lt;span style=&#39;color:#808030; &#39;&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style=&#39;color:#400000; &#39;&gt;puts&lt;/span&gt; &lt;span style=&#39;color:#0000e6; &#39;&gt;&quot;#{ENV[&#39;RAILS_ENV&#39;]} Solr started sucessfuly on #{SOLR_PORT}, pid: #{pid}.&quot;&lt;/span&gt;&lt;br /&gt;      &lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Steps to configure solr in our application&lt;br /&gt;&lt;br /&gt;1) Starts the solr server&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;rake solr:start&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;2) Changes to ActiveRecord model&lt;br /&gt;   acts_as_solr - all fields are indexed&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;&lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;class&lt;/span&gt; News &amp;lt; ActiveRecord::Base&lt;br /&gt;     acts_as_solr :fields &lt;span style=&#39;color:#808030; &#39;&gt;=&lt;/span&gt;&gt; &lt;span style=&#39;color:#808030; &#39;&gt;[&lt;/span&gt;:title, :content&lt;span style=&#39;color:#808030; &#39;&gt;]&lt;/span&gt; &lt;br /&gt;   &lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;   – specified fields are indexed&lt;br /&gt;We can specify the name of the fields to be used for searching.&lt;br /&gt;  Options:&lt;br /&gt;  :if =&gt; we can supply any condition as string, proc, symbol, method. It will index the record only if condition returns true.&lt;br /&gt;&lt;br /&gt;3) Do index/reindex&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;rake solr:reindex&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;4) Changes to Controller&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;News&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;find_by_solr&lt;span style=&#39;color:#808030; &#39;&gt;(&lt;/span&gt;query&lt;span style=&#39;color:#808030; &#39;&gt;)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;query =&gt; query is a string representing your query&lt;br /&gt;  &lt;br /&gt;There are many options available in solr, we can do a refined search by using SOLR.&lt;br /&gt;&lt;br /&gt;Problem:&lt;br /&gt;I faced one problem, acts_as_solr :if option is not working with rake task to reindex data. Instead of checking the condition it will simply indexes all the records. But other method like solr_save() checks the condition passed with acts_as_solr definition in model. I have added a patch to check the condition in rake task &#39;reindex&#39;.&lt;br /&gt;&lt;br /&gt;file path: acts_as_solr\lib\class_methods.rb&lt;br /&gt;line no: 200 - 250&lt;br /&gt;method name: rebuild_solr_index&lt;br /&gt;Instead of normal collect,&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;items&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;collect! &lt;span style=&#39;color:#800080; &#39;&gt;{&lt;/span&gt; |content| content&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;to_solr_doc &lt;span style=&#39;color:#800080; &#39;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We can use the following code, to filter the records with the condition defined in model and collect the remaining results&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;items &lt;span style=&#39;color:#808030; &#39;&gt;=&lt;/span&gt; items&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;&lt;span style=&#39;color:#400000; &#39;&gt;select&lt;/span&gt; &lt;span style=&#39;color:#800080; &#39;&gt;{&lt;/span&gt; |content| content&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;evaluate_condition_public&lt;span style=&#39;color:#808030; &#39;&gt;(&lt;/span&gt;content&lt;span style=&#39;color:#808030; &#39;&gt;)&lt;/span&gt;&lt;span style=&#39;color:#800080; &#39;&gt;}&lt;/span&gt;&lt;br /&gt;items&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;collect! &lt;span style=&#39;color:#800080; &#39;&gt;{&lt;/span&gt; |content| content&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;to_solr_doc &lt;span style=&#39;color:#800080; &#39;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;After doing the above changes, you can have a correct data in your search results. This is applicable only when we are using acts_as_solr with conditions in model.&lt;br /&gt;&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;acts_as_solr :fields &lt;span style=&#39;color:#808030; &#39;&gt;=&lt;/span&gt;&gt; &lt;span style=&#39;color:#808030; &#39;&gt;[&lt;/span&gt;&lt;span style=&#39;color:#0000e6; &#39;&gt;&quot;name&quot;&lt;/span&gt;,&lt;span style=&#39;color:#0000e6; &#39;&gt;&quot;description&quot;&lt;/span&gt;&lt;span style=&#39;color:#808030; &#39;&gt;]&lt;/span&gt;, :&lt;span style=&#39;color:#800000; font-weight:bold; &#39;&gt;if&lt;/span&gt; &lt;span style=&#39;color:#808030; &#39;&gt;=&lt;/span&gt;&gt; &lt;span style=&#39;color:#400000; &#39;&gt;proc&lt;/span&gt;&lt;span style=&#39;color:#800080; &#39;&gt;{&lt;/span&gt;|record| record&lt;span style=&#39;color:#808030; &#39;&gt;.&lt;/span&gt;active?&lt;span style=&#39;color:#800080; &#39;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Hope, this is useful for someone who is using acts_as_solr with :if option.&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Vadivelan</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/8429622821822882528/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2011/10/solr.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/8429622821822882528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/8429622821822882528'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2011/10/solr.html' title='Solr'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-3262536761748331695</id><published>2011-08-18T04:18:00.000-07:00</published><updated>2011-08-18T04:27:50.580-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="assert_tag in rails"/><category scheme="http://www.blogger.com/atom/ns#" term="functional testing in rails"/><category scheme="http://www.blogger.com/atom/ns#" term="test text field select_tag div img in rails functionals testing"/><title type='text'>Functional Testing in Rails(to test Html)</title><content type='html'>Hi all,&lt;br /&gt;&lt;br /&gt;I have used listed out some uses of assert_tag in Rails functional test. In many case, we need to test the html content of page like checkbox is checked or not, text fields holds correct value, drop down selected with correct option. For those kind of needs, we need to go for &lt;span style=&quot;font-style:italic;&quot;&gt;assert_tag&lt;/span&gt;. Below are the example usage of assert_tag in functional testing.&lt;br /&gt;&lt;br /&gt;In Rails html testing, assert_tag method plays an vital role. Following are some of the ways to use assert_tag method&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Get links inside div&lt;br /&gt;&lt;br /&gt;assert_select &quot;div#divID&quot; do&lt;br /&gt;		assert_select &quot;a[href=?]&quot;, &quot;/path/to/some/page&quot;&lt;br /&gt;end &lt;br /&gt;&lt;br /&gt;Check the content of any html element(here is an example for Div)&lt;br /&gt;		&lt;br /&gt;		by className&lt;br /&gt;		assert_select &quot;div.className&quot;, &quot;Page Heading or content inside the div&quot;&lt;br /&gt;		by element ID&lt;br /&gt;		assert_select &quot;div#elementId&quot;, &quot;Page Heading or content inside the div&quot;&lt;br /&gt;&lt;br /&gt;Check how many times any DOM element appears on the page:&lt;br /&gt;&lt;br /&gt;In the below example, we tested how many number of user images loaded on the page&lt;br /&gt;assert_select &quot;div.className table tr td.userImage img&quot;, {:count =&gt; 4}&lt;br /&gt;&lt;br /&gt;Presence of Textbox:&lt;br /&gt;&lt;br /&gt;assert_tag &quot;input&quot;, :attributes =&gt; {:id =&gt; &quot;user_screen_name&quot;, :size =&gt; &quot;30&quot;, :type =&gt; &quot;text&quot;}&lt;br /&gt;&lt;br /&gt;Get value of Dropdown:&lt;br /&gt;&lt;br /&gt;option = css_select(&quot;select#elementId option[selected=&#39;selected&#39;]&quot;)[0]&lt;br /&gt;assert_equal &quot;public&quot;, option[&#39;value&#39;].to_s&lt;br /&gt;&lt;br /&gt;Code with testcase improves the quality of code and at the sametime reduces the errors. Keep writing test for each line of code.</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/3262536761748331695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2011/08/functionals-testing-in-railsto-test.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/3262536761748331695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/3262536761748331695'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2011/08/functionals-testing-in-railsto-test.html' title='Functional Testing in Rails(to test Html)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-2569258973083582517</id><published>2011-04-18T06:41:00.000-07:00</published><updated>2011-10-20T02:59:15.810-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="find in windows"/><category scheme="http://www.blogger.com/atom/ns#" term="grep command"/><category scheme="http://www.blogger.com/atom/ns#" term="grep in windows"/><title type='text'>Alternative to &quot;grep&quot; command in Windows</title><content type='html'>Hi all,&lt;br /&gt;&lt;br /&gt;I have shifted from ubuntu and started using windowsXP. When I tried to use the grep command in windows, it throws the error&lt;br /&gt;&lt;br /&gt;Instead of using grep, we can use find&lt;br /&gt;&lt;pre style=&#39;color:#000000;background:#ffffff;&#39;&gt;gem list|find &lt;span style=&#39;color:#0000e6; &#39;&gt;&quot;rails&quot;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;rails (3.0.10)&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Vadivelan</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/2569258973083582517/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2011/04/alternative-to-grep-command-in-windows.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/2569258973083582517'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/2569258973083582517'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2011/04/alternative-to-grep-command-in-windows.html' title='Alternative to &quot;grep&quot; command in Windows'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-5470631268352243953</id><published>2011-02-02T01:27:00.000-08:00</published><updated>2011-02-02T01:37:01.396-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="group by month"/><category scheme="http://www.blogger.com/atom/ns#" term="order by month and year"/><category scheme="http://www.blogger.com/atom/ns#" term="post count display"/><category scheme="http://www.blogger.com/atom/ns#" term="post count plus month display"/><title type='text'>Month with number of count display for any model in your application</title><content type='html'>By using rails finder method, it is very easy to display the number of post and month accordingly.&lt;br /&gt;Here is the query&lt;br /&gt;&lt;br /&gt;&gt;&gt; Post.count(:order =&gt; &#39;DATE(created_at) DESC&#39;, :group =&gt; [&quot;DATE_FORMAT(created_at,&#39;%m/%Y&#39;)&quot;])&lt;br /&gt;=&gt; #&lt; OrderedHash {&quot;06/2010&quot;=&gt;1, &quot;03/2010&quot;=&gt;1, &quot;02/2010&quot;=&gt;1}&gt;&lt;br /&gt;&lt;br /&gt;Result is a collection hash ordered in the form of latest month as first one, Collection contains the month as Key and number of count as Value. &lt;br /&gt;&lt;br /&gt;If we run it through the each loop and it is very easy to display.&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;Vadivelan</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/5470631268352243953/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2011/02/month-with-number-of-count-display-for.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/5470631268352243953'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/5470631268352243953'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2011/02/month-with-number-of-count-display-for.html' title='Month with number of count display for any model in your application'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-7565451331535338959</id><published>2011-01-10T00:47:00.000-08:00</published><updated>2011-01-10T00:49:23.519-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ruby keywords"/><title type='text'>Ruby keywords</title><content type='html'>List of ruby keywords&lt;br /&gt;&lt;br /&gt;1. alias&lt;br /&gt;2. and&lt;br /&gt;3. BEGIN&lt;br /&gt;4. begin&lt;br /&gt;5. break&lt;br /&gt;6. case&lt;br /&gt;7. class&lt;br /&gt;8. def&lt;br /&gt;9. defined&lt;br /&gt;10. do&lt;br /&gt;11. else&lt;br /&gt;12. elsif&lt;br /&gt;13. END&lt;br /&gt;14. end&lt;br /&gt;15. ensure&lt;br /&gt;16. false&lt;br /&gt;17. for&lt;br /&gt;18. if&lt;br /&gt;19. in&lt;br /&gt;20. module&lt;br /&gt;21. next&lt;br /&gt;22. nil&lt;br /&gt;23. not&lt;br /&gt;24. or&lt;br /&gt;25. redo&lt;br /&gt;26. rescue&lt;br /&gt;27. retry&lt;br /&gt;28. return&lt;br /&gt;29. self&lt;br /&gt;30. super&lt;br /&gt;31. then&lt;br /&gt;32. true&lt;br /&gt;33. undef&lt;br /&gt;34. unless&lt;br /&gt;35. until&lt;br /&gt;36. when&lt;br /&gt;37. while&lt;br /&gt;38. yield</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/7565451331535338959/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2011/01/ruby-keywords.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/7565451331535338959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/7565451331535338959'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2011/01/ruby-keywords.html' title='Ruby keywords'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-6532595902679533513</id><published>2011-01-09T23:32:00.000-08:00</published><updated>2011-01-10T00:46:55.943-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="order by field"/><category scheme="http://www.blogger.com/atom/ns#" term="order by field option"/><category scheme="http://www.blogger.com/atom/ns#" term="order by name"/><category scheme="http://www.blogger.com/atom/ns#" term="rails order  by"/><category scheme="http://www.blogger.com/atom/ns#" term="sql order by"/><title type='text'>SQL order_by &quot;field&quot; option</title><content type='html'>Hi all,&lt;br /&gt;&lt;br /&gt;I tried to order the SQL results in a pre-defined order. Consider the case&lt;br /&gt;&lt;br /&gt;Am having users table, and a field called &#39;status&#39; to store the current status of the user.&lt;br /&gt;In back-end of my site, am displaying all the users with order-by &#39;status&#39;&lt;br /&gt;&lt;br /&gt;Possible status values are &quot;Pending&quot;, &quot;Approved&quot;, &quot;Canceled&quot;, &quot;Deleted&quot;&lt;br /&gt;&lt;br /&gt;I need to display users in the following orders, &lt;br /&gt;&quot;Approved&quot;, &quot;Pending&quot;, &quot;Canceled&quot;, &quot;Deleted&quot;&lt;br /&gt;&lt;br /&gt;The normal order by field orders the field in either ASC/DESC. But in this case it is different.&lt;br /&gt;For this i used the following query to fetch SQL results in a defined order&lt;br /&gt;&lt;br /&gt;Rails finder: &lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;User.find_by_sql(&quot;select * from users order by field (status,&#39;Approved&#39;, &#39;Pending&#39;, &#39;Canceled&#39;, &#39;Deleted&#39;)&quot;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL query:&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;select * from users order by field (status,&#39;Approved&#39;, &#39;Pending&#39;, &#39;Canceled&#39;, &#39;Deleted&#39;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Result contains the collection in the defined order.&lt;br /&gt;&lt;br /&gt;When you are using this &quot;order by field&quot; option, you have to give all the option in the order  then only it will works.&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;Vadivelan</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/6532595902679533513/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2011/01/sql-orderby-field-option.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/6532595902679533513'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/6532595902679533513'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2011/01/sql-orderby-field-option.html' title='SQL order_by &quot;field&quot; option'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-3625972589599748383</id><published>2010-11-10T19:28:00.000-08:00</published><updated>2010-11-10T19:30:23.797-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="active record base increment and decrement"/><category scheme="http://www.blogger.com/atom/ns#" term="active record decrement field"/><category scheme="http://www.blogger.com/atom/ns#" term="active record increment field"/><category scheme="http://www.blogger.com/atom/ns#" term="update_attribute"/><title type='text'>ActiveRecord::Base increment &amp; decrement method</title><content type='html'>Hi all,&lt;br /&gt;&lt;br /&gt;Yesterday while i was working in a task, i need to increase the points of an user. For that i have used the update_attribute method like below&lt;br /&gt; &lt;br /&gt;user = User.last &lt;br /&gt;user.update_attribute(:points, 5)&lt;br /&gt;&lt;br /&gt;Then i found the active record base in-built method called &quot;increment&quot; and &quot;decrement&quot;. So i used the following method to increment/decrement the user points. &lt;br /&gt;&lt;br /&gt;user.increment(:points) # it will increase points by 1(default increment count) and returns the user object(self)&lt;br /&gt;user.save&lt;br /&gt;user.increment!(:points) # and this one will do the above two operations i.e., assigns the value to the attribute and saves the record. It will returns true or false(validation result).&lt;br /&gt;&lt;br /&gt;user.increment(:points, 5) # we can pass the value like this to increment the attribute by this much. Here points will increases by 5&lt;br /&gt;user.save&lt;br /&gt;user.increment!(:points, 5)&lt;br /&gt;&lt;br /&gt;The same is applicable to the &quot;decrement&quot; method, syntax is given below&lt;br /&gt;user.decrement(:points)&lt;br /&gt;user.decrement!(:points)&lt;br /&gt;user.decrement(:points, 5)&lt;br /&gt;user.decrement!(:points, 5)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;Vadivelan</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/3625972589599748383/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2010/11/activerecordbase-increment-decrement.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/3625972589599748383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/3625972589599748383'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2010/11/activerecordbase-increment-decrement.html' title='ActiveRecord::Base increment &amp; decrement method'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-2906716706784768504</id><published>2010-10-06T21:52:00.000-07:00</published><updated>2010-10-06T22:10:04.192-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="app.get"/><category scheme="http://www.blogger.com/atom/ns#" term="app.post"/><category scheme="http://www.blogger.com/atom/ns#" term="console app"/><category scheme="http://www.blogger.com/atom/ns#" term="rails console"/><category scheme="http://www.blogger.com/atom/ns#" term="script/console"/><title type='text'>Use of rails console</title><content type='html'>Hi all,&lt;br /&gt;&lt;br /&gt;We can use our rails console(powerful tool for rails app) for debugging and testing. Mainly console helps us to learn more about Ruby&lt;br /&gt; &lt;br /&gt;Normally we are using console to talk with our database, and fetch the objects from db.&lt;br /&gt;ex: &lt;br /&gt;User.first&lt;br /&gt;User.all&lt;br /&gt;&lt;br /&gt;But apart from that we can use our console to interact with our application using the object &quot;app&quot;&lt;br /&gt;&quot;app&quot;&lt;br /&gt;&lt;br /&gt;app.class    # returns this&lt;br /&gt;ActionController::Integration::Session&lt;br /&gt;&lt;br /&gt;we can fire(get/post) requests to our application from console itself.&lt;br /&gt;&lt;br /&gt;&gt;&gt; app.get &quot;/login&quot;&lt;br /&gt;=&gt; 200&lt;br /&gt;it returns the status code for the handled request&lt;br /&gt; &lt;br /&gt;&gt;&gt; app.post &quot;/user_sessions&quot;, :user_session =&gt; {:email =&gt; &#39;vadivelan@example.com&#39;, :password =&gt; &#39;secret&#39;}&lt;br /&gt;=&gt; 302&lt;br /&gt;we can send post request with parameters like this&lt;br /&gt;&lt;br /&gt;&gt;&gt; app.response.redirect?&lt;br /&gt;=&gt; true&lt;br /&gt;redirected to some other url&lt;br /&gt;&lt;br /&gt;&gt;&gt; app.response.redirect_url&lt;br /&gt;=&gt; &quot;http://localhost/login&quot;&lt;br /&gt;view the redirect url &lt;br /&gt;&lt;br /&gt;Hope now you guys can start firing the requests to application from console.&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;Vadivelan</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/2906716706784768504/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2010/10/use-of-rails-console.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/2906716706784768504'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/2906716706784768504'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2010/10/use-of-rails-console.html' title='Use of rails console'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-8140232024966794906</id><published>2010-09-24T04:56:00.000-07:00</published><updated>2010-09-27T07:06:26.172-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="instance method call using send"/><category scheme="http://www.blogger.com/atom/ns#" term="method call"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby send"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby send method"/><title type='text'>ruby send method</title><content type='html'>Hi all&lt;br /&gt;&lt;br /&gt;I am started using the method named &quot;send&quot;.&lt;br /&gt;&lt;br /&gt;We can use this to call the method using object.&lt;br /&gt;&lt;br /&gt;class User&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt; &lt;br /&gt;def say_hello&lt;br /&gt;&quot;Hello&quot;&lt;br /&gt;end &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;u = User.new&lt;br /&gt;puts u.send(:say_hello)&lt;br /&gt;&lt;br /&gt;Here the class &quot;User&quot; is having the method called say_hello. We can create an object for the user class and call the method using the method &quot;send&quot;&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;vadivelan</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/8140232024966794906/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2010/09/ruby-send-method.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/8140232024966794906'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/8140232024966794906'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2010/09/ruby-send-method.html' title='ruby send method'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-7432895291761350539</id><published>2010-09-21T11:14:00.000-07:00</published><updated>2010-09-21T11:26:50.250-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="extend method"/><category scheme="http://www.blogger.com/atom/ns#" term="instance method"/><category scheme="http://www.blogger.com/atom/ns#" term="multiple inheritance"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby module"/><title type='text'>ruby extend method</title><content type='html'>Hi all,&lt;br /&gt;&lt;br /&gt;I have seen the method named &quot;extend&quot; used in a line of code in Plugin. Then i started searching for the use of method &quot;extend&quot;. And i found the following&lt;br /&gt;&lt;br /&gt;consider the example&lt;br /&gt;&lt;br /&gt;module Friend&lt;br /&gt; def say_hello&lt;br /&gt;  &quot;hello am inside module&quot;&lt;br /&gt; end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;class Person&lt;br /&gt; def say_hello&lt;br /&gt;  &quot;hello am inside class&quot;&lt;br /&gt; end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;p = Person.new&lt;br /&gt;puts p.say_hello  #=&gt; hello am inside class&lt;br /&gt;&lt;br /&gt;p.extend(Friend) #=&gt; include all the instance method from Module &quot;Friend&quot;&lt;br /&gt;puts p.say_hello #=&gt; hello am inside module&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So the extend method is used to include the Module.&lt;br /&gt;Without this we cannot call the method inside the module using the Person object. Even if i added include the module in the class, it wont calls the module method. The instance method inside the class gets called for the object(Person class).</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/7432895291761350539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2010/09/ruby-extend-method.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/7432895291761350539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/7432895291761350539'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2010/09/ruby-extend-method.html' title='ruby extend method'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-2651199111333736016</id><published>2010-09-15T23:54:00.000-07:00</published><updated>2010-09-16T00:08:22.200-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="blocks"/><category scheme="http://www.blogger.com/atom/ns#" term="Proc"/><category scheme="http://www.blogger.com/atom/ns#" term="proc.call"/><title type='text'>Use of Proc &amp; proc</title><content type='html'>Hi &lt;br /&gt;&lt;br /&gt;I have used &quot;proc&quot; to run/block validation in model. But now i learned something more about proc. &lt;br /&gt;In ruby, &quot;Proc&quot;(procedure) refers to the block of code, we can reuse it. Block of code assigned to the object.&lt;br /&gt;&lt;br /&gt;&quot;Proc&quot; =&gt; Starts with capital letter refers to (class name)&lt;br /&gt;&quot;proc&quot; =&gt; Refers to the proc object&lt;br /&gt;&lt;br /&gt;We can use both the keywords to create a proc by defining any block to them.&lt;br /&gt;&lt;br /&gt;below sample code to create a proc and call that proc to execute the block of code&lt;br /&gt;&lt;br /&gt;accepts_any_arg = Proc.new{ |a,b,c|&lt;br /&gt; puts &quot;#{a}  #{b}  #{c}&quot;&lt;br /&gt;}&lt;br /&gt;accepts_any_arg.call(1)&lt;br /&gt; result: 1&lt;br /&gt;accepts_any_arg.call(1,2) &lt;br /&gt; result: 1  2&lt;br /&gt;It just neglects the number of arguments required or passing to that proc, it is working without any argument error. It assigns nil value to arguments which are not passed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;throws_args_error = proc{ |a,b,c|&lt;br /&gt; puts &quot;#{a}  #{b}  #{c}&quot;&lt;br /&gt;}&lt;br /&gt;throws_args_error.call(1,2,3)&lt;br /&gt;  result: 1  2  3&lt;br /&gt;throws_args_error.call(1)&lt;br /&gt;  result: Throws &quot;ArgumentError&quot;&lt;br /&gt;it is checking the number of arguments&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;Vadivelan</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/2651199111333736016/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2010/09/use-of-proc-proc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/2651199111333736016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/2651199111333736016'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2010/09/use-of-proc-proc.html' title='Use of Proc &amp; proc'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-6802253290024953739</id><published>2010-07-22T08:10:00.001-07:00</published><updated>2010-07-22T08:18:35.071-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="defined?"/><category scheme="http://www.blogger.com/atom/ns#" term="local variable"/><category scheme="http://www.blogger.com/atom/ns#" term="rails defined"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby defined"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby variable"/><title type='text'>Ruby - &quot;defined?&quot; method</title><content type='html'>Hi all,&lt;br /&gt;&lt;br /&gt;In ruby we are having many methods to check whether the variable defined or not. Mostly we are using the following condition to check the variable defined or not&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;if local_variable&lt;br /&gt; puts &quot;local variable exists&quot;&lt;br /&gt;else&lt;br /&gt; puts &quot;local_variable does not exists&quot;&lt;br /&gt;end &lt;br /&gt;&lt;br /&gt;But there is another way to check the variable defined or not.&lt;br /&gt;&lt;br /&gt;sample-code:&lt;br /&gt;&lt;br /&gt;a = 10&lt;br /&gt;puts defined?(a).inspect =&gt; &quot;local-variable&quot;&lt;br /&gt;puts defined?(b).inspect =&gt; nil&lt;br /&gt;&lt;br /&gt;So, the method returns the value &quot;local-variable&quot; for the already defined variables and &quot;nil&quot; for the undefined variables.&lt;br /&gt;&lt;br /&gt;Hope hereafter you guys using the method &quot;defined?&quot; to check the variable already defined or not.&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Vadivelan</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/6802253290024953739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2010/07/ruby-defined-method.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/6802253290024953739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/6802253290024953739'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2010/07/ruby-defined-method.html' title='Ruby - &quot;defined?&quot; method'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-7489976998390618118</id><published>2010-05-24T20:54:00.000-07:00</published><updated>2010-05-24T21:05:30.750-07:00</updated><title type='text'>ruby math functions</title><content type='html'>Hi all,&lt;br /&gt;&lt;br /&gt;Here i have listed some of the most frequently used math functions in ruby.&lt;br /&gt;&lt;br /&gt;round method rounds the value &lt;br /&gt;if decimal value is less than .5, rounded to its lowest value&lt;br /&gt;irb(main):006:0&gt; 1.2.round&lt;br /&gt;=&gt; 1&lt;br /&gt;if decimal value is greater than .4, rounded to its highest value&lt;br /&gt;irb(main):007:0&gt; 1.5.round&lt;br /&gt;=&gt; 2&lt;br /&gt;&lt;br /&gt;floor method rounded the value to lowest value&lt;br /&gt;irb(main):008:0&gt; 1.5.floor&lt;br /&gt;=&gt; 1&lt;br /&gt;&lt;br /&gt;ceil method rounded the value to next highest value&lt;br /&gt;irb(main):009:0&gt; 1.5.ceil&lt;br /&gt;=&gt; 2&lt;br /&gt;&lt;br /&gt;&#39;nan&#39; method used to check whether the value is integer or not&lt;br /&gt;irb(main):010:0&gt; x = 0.0/0.0&lt;br /&gt;=&gt; NaN&lt;br /&gt;&lt;br /&gt;irb(main):011:0&gt; x.nan?&lt;br /&gt;=&gt; true&lt;br /&gt;&lt;br /&gt;Get ASCII value&lt;br /&gt;irb(main):017:0&gt; Integer(?e)&lt;br /&gt;=&gt; 101&lt;br /&gt;&lt;br /&gt;irb(main):018:0&gt; Float(?e)&lt;br /&gt;=&gt; 101.0&lt;br /&gt;&lt;br /&gt;&gt;&gt; &quot;%.2f&quot; % (1.0/2.0)&lt;br /&gt;=&gt; &quot;0.50&quot;&lt;br /&gt;&lt;br /&gt;The last method is mainly used for display purpose. We have to display the floating point number in any page(say to display the cost) we must modify the output in such a way to get clear display(Max of 2 numbers after decimal point in this case).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;Vadivelan</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/7489976998390618118/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2010/05/ruby-math-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/7489976998390618118'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/7489976998390618118'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2010/05/ruby-math-functions.html' title='ruby math functions'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-4458195590873519495</id><published>2010-05-24T20:45:00.000-07:00</published><updated>2010-05-24T20:53:41.426-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="$"/><category scheme="http://www.blogger.com/atom/ns#" term="$A"/><category scheme="http://www.blogger.com/atom/ns#" term="$F"/><category scheme="http://www.blogger.com/atom/ns#" term="$W"/><category scheme="http://www.blogger.com/atom/ns#" term="prototype.js"/><category scheme="http://www.blogger.com/atom/ns#" term="rails prototype js"/><title type='text'>Some more uses of &#39;$&#39; in prototype javascript</title><content type='html'>Hi all,&lt;br /&gt;&lt;br /&gt;We are all using the &#39;$&#39; in prototype javascript to get the object of the matched DOM element by using id of the element.&lt;br /&gt;&lt;br /&gt;Say for example:&lt;br /&gt;&lt;br /&gt;the page has the div element &lt;br /&gt;&lt;div id=&#39;container&#39;&gt;&lt;br /&gt;   content inside the div element &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;To get the object of the div element we are using the &#39;$&#39;.&lt;br /&gt;&lt;br /&gt;$(&#39;container&#39;) =&gt; returns the object of the DOM element.&lt;br /&gt;&lt;br /&gt;$A/$W/$F =&gt; are also available but rarely used..&lt;br /&gt;&lt;br /&gt;the below lines explain the use of the $A/$W/$F&lt;br /&gt;&lt;br /&gt;// converts a string into array, each element is taken as a count&lt;br /&gt;&gt;&gt;&gt; $A(&#39;1&#39;)&lt;br /&gt;[&#39;1&#39;]&lt;br /&gt;&gt;&gt;&gt; $A(&#39;123&#39;)&lt;br /&gt;[&quot;1&quot;, &quot;2&quot;, &quot;3&quot;]&lt;br /&gt;&lt;br /&gt;// converts a string into array, it takes whitespace as delimiters&lt;br /&gt;&gt;&gt;&gt; $w(&#39;1 2 3&#39;)&lt;br /&gt;[&quot;1&quot;, &quot;2&quot;, &quot;3&quot;]&lt;br /&gt;&lt;br /&gt;// used to get values of text field which is located inside any forms&lt;br /&gt;// same as Form.Element.getValue&lt;br /&gt;&gt;&gt;&gt; $F(&#39;press_room_url&#39;)&lt;br /&gt;&lt;br /&gt;So start using these commands makes the code simpler.. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;Vadivelan</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/4458195590873519495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2010/05/some-more-uses-of-in-prototype.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/4458195590873519495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/4458195590873519495'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2010/05/some-more-uses-of-in-prototype.html' title='Some more uses of &#39;$&#39; in prototype javascript'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-1087927664716773792</id><published>2010-03-31T21:48:00.000-07:00</published><updated>2010-03-31T21:57:14.935-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jquery"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery conflict"/><category scheme="http://www.blogger.com/atom/ns#" term="jquery with rails"/><title type='text'>jQuery with rails</title><content type='html'>Hi all,&lt;br /&gt;&lt;br /&gt;I have used the jquery js prototype recently, it has lots of more usage than our prototype.js. Easy to code using jQuery.js.&lt;br /&gt;&lt;br /&gt;But in my rails application i have used both prototype.js &amp; jquery.js. In this situation the $ gets conflict. To avoid conflict, use the line of code&lt;br /&gt;&lt;br /&gt;First include prototype.js, then add jQuery.js after that you must add this line to avoid ($)conflict&lt;br /&gt;&lt;script&gt;&lt;br /&gt;var $j = jQuery.noConflict();&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;Once you done this, you can enjoy the usage of both prototype.js &amp; jQuery.js.&lt;br /&gt;&lt;br /&gt;i.e., both $ and $j is available to access.&lt;br /&gt;&lt;br /&gt;$(&#39;id_of_dom_elemnt&#39;) =&gt; returns (prototype)object of the html element&lt;br /&gt;$j(&#39;#id_of_dom_element&#39;) =&gt; return (jquery)object of the html element&lt;br /&gt;&lt;br /&gt;In jQuery, we have to add &#39;#&#39; symbol with id of dom element to find the element.&lt;br /&gt;&lt;br /&gt;Enjoy coding with jQuery... &lt;br /&gt;&lt;br /&gt;thanks,</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/1087927664716773792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2010/03/jquery-with-rails.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/1087927664716773792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/1087927664716773792'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2010/03/jquery-with-rails.html' title='jQuery with rails'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-4923037709322684898</id><published>2010-01-23T02:04:00.000-08:00</published><updated>2010-01-23T02:13:44.992-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript object"/><category scheme="http://www.blogger.com/atom/ns#" term="js array"/><category scheme="http://www.blogger.com/atom/ns#" term="json"/><category scheme="http://www.blogger.com/atom/ns#" term="Object in array"/><title type='text'>JSON startup</title><content type='html'>JSON - javascript object notation&lt;br /&gt;&lt;br /&gt;To know about the JSON, first go through the following basics in js.&lt;br /&gt;&lt;br /&gt;Array:&lt;br /&gt;&lt;br /&gt;var arr = new Array(&quot;first&quot;, &quot;second&quot;, &quot;third&quot;, &quot;fourth&quot;);&lt;br /&gt;&lt;br /&gt;Retrieve value from array&lt;br /&gt;&lt;br /&gt;arr[0]  =&gt; &quot;first&quot;&lt;br /&gt;arr[1]  =&gt; &quot;second&quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object:&lt;br /&gt;&lt;br /&gt;var sample_object = {&lt;br /&gt; &quot;name1&quot; : &quot;value1&quot;,&lt;br /&gt; &quot;name2&quot; : &quot;value2&quot;,&lt;br /&gt; &quot;name3&quot; : &quot;value3&quot;,&lt;br /&gt; &quot;name4&quot; : &quot;value4&quot;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;sample_object.name1  =&gt; &quot;value1&quot;&lt;br /&gt;sample_object[&quot;name1&quot;]  =&gt; &quot;value1&quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Objects in Array&lt;br /&gt;&lt;br /&gt;var object_array = [&lt;br /&gt; {&lt;br /&gt;  &quot;first_element&quot; : &quot;first_value&quot;&lt;br /&gt; },&lt;br /&gt; {&lt;br /&gt;  &quot;second_element&quot; : &quot;second_value&quot;&lt;br /&gt; }&lt;br /&gt;]&lt;br /&gt;object_array[0]  =&gt; returns first object &lt;br /&gt;object_array[1].second_element  =&gt; second object value&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Arrays in Object:&lt;br /&gt;&lt;br /&gt;var sample_object = {&lt;br /&gt; &quot;name1&quot; : &quot;value1&quot;,&lt;br /&gt; &quot;name4&quot; : [1,2,3,4]&lt;br /&gt;}&lt;br /&gt;sample_object.name4  =&gt; [1,2,3,4]&lt;br /&gt;sample_object.name4[0]  =&gt; 1&lt;br /&gt;&lt;br /&gt;var str_json = JSON.stringify(sample_object);&lt;br /&gt;var js_object = JSON.parse(str_json);&lt;br /&gt;JSON.parse(strJSON) - converts a JSON string into a JavaScript object.&lt;br /&gt;JSON.stringify(objJSON) - converts a JavaScript object into a JSON string.</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/4923037709322684898/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2010/01/json-startup.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/4923037709322684898'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/4923037709322684898'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2010/01/json-startup.html' title='JSON startup'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-4670038696127529851</id><published>2009-12-07T18:33:00.000-08:00</published><updated>2009-12-07T18:42:37.593-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="watir select box"/><category scheme="http://www.blogger.com/atom/ns#" term="watir text field"/><title type='text'>Watir tips</title><content type='html'>Hi Guys,&lt;br /&gt;&lt;br /&gt;Waitr is a ruby gem used in testing. It has many uses, mostly it is used to control the web browser(all html dom elements as objects).&lt;br /&gt;&lt;br /&gt;installation command:-&lt;br /&gt;gem install waitr&lt;br /&gt;&lt;br /&gt;Some sample use of watir&lt;br /&gt;&lt;br /&gt;1. Starting a new Web browser&lt;br /&gt;require &#39;watir&#39;&lt;br /&gt;ie = Watir::Browser.new&lt;br /&gt;ie.goto(&quot;http://www.google.com&quot;)&lt;br /&gt;&lt;br /&gt;2. Starting a firefox browser&lt;br /&gt;require &#39;watir&#39;&lt;br /&gt;Watir::Browser.default = &quot;firefox&quot;&lt;br /&gt;ff = Watir::Browser.start(&quot;http://www.google.com&quot;)&lt;br /&gt;&lt;br /&gt;3.Setting a text field with some value&lt;br /&gt;&lt;br /&gt;ie.text_field(:name, &quot;username&quot;).set &quot;Vaddi&quot;&lt;br /&gt;&lt;br /&gt;4. Setting value of select list&lt;br /&gt;&lt;br /&gt;ie.select_list( :name , &quot;category&quot;).select(&quot;Comedy&quot;)&lt;br /&gt;&lt;br /&gt;For all the DOM elements, it has objects(for text box - &#39;text_field&#39;, for drop down - &#39;select_list&#39;)&lt;br /&gt;&lt;br /&gt;thanks,</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/4670038696127529851/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2009/12/watir-tips.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/4670038696127529851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/4670038696127529851'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2009/12/watir-tips.html' title='Watir tips'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-5253603130591391784</id><published>2009-12-04T18:46:00.000-08:00</published><updated>2009-12-04T21:44:50.565-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="foreach method"/><category scheme="http://www.blogger.com/atom/ns#" term="js array collect"/><category scheme="http://www.blogger.com/atom/ns#" term="js array for loop"/><title type='text'>for loop - js</title><content type='html'>In javascript, to read the array index and their appropriate value.&lt;br /&gt;&lt;br /&gt;Use the following way,&lt;br /&gt;&lt;br /&gt;var a = Array.new(); declare new array with name &#39;a&#39;&lt;br /&gt;a = [1,2,3,4,5];  assign some values to array&lt;br /&gt;var indexes = function show(value, indx){&lt;br /&gt;    alert(indx);&lt;br /&gt;    alert(value);&lt;br /&gt;}&lt;br /&gt;a.forEach(indexes);&lt;br /&gt;&#39;forEach&#39; method is used to collect the values from the array.&lt;br /&gt;&lt;br /&gt;By using the method &#39;forEach&#39;, we can collect each element from array.&lt;br /&gt;&lt;br /&gt;Try this..</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/5253603130591391784/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2009/12/for-loop-js.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/5253603130591391784'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/5253603130591391784'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2009/12/for-loop-js.html' title='for loop - js'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7962756704981038195.post-3238777931371679412</id><published>2009-11-30T01:06:00.000-08:00</published><updated>2009-11-30T01:10:51.119-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="add fav icon"/><category scheme="http://www.blogger.com/atom/ns#" term="favicon"/><title type='text'>Add favicon image to your site</title><content type='html'>Its very easy to add favicon to ur site by following steps&lt;br /&gt;&lt;br /&gt;include the line in your layout head&lt;br /&gt;html link tag &lt;br /&gt;with attributes &lt;br /&gt;rel=&quot;icon&quot; href=&quot;favicon_path&quot; &lt;br /&gt;type=&quot;image/x-icon&quot;&lt;br /&gt;&lt;br /&gt;favicon_path = image path of favicon&lt;br /&gt;&lt;br /&gt;That&#39;s it...&lt;br /&gt;&lt;br /&gt;Try with this..</content><link rel='replies' type='application/atom+xml' href='http://vaddi-blog.blogspot.com/feeds/3238777931371679412/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vaddi-blog.blogspot.com/2009/11/add-favicon-image-to-your-site.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/3238777931371679412'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7962756704981038195/posts/default/3238777931371679412'/><link rel='alternate' type='text/html' href='http://vaddi-blog.blogspot.com/2009/11/add-favicon-image-to-your-site.html' title='Add favicon image to your site'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>