Thursday, September 30, 2010

Moving rails app from 2.3.5 to 2.3.9

In my last post, at the end, I mentioned about migrating my rails app from version 2.3.5 to 2.3.9 for making it more closer to rails 3.0. I worked on the same and it went well. I localized rack-1.1.0 version as rails 2.3.9 has this dependency. Most of the steps that I followed were similar to my earlier post except the change in version number.

Listing the deprecation warnings that need to be fixed that I received during the migration :-

(1) DEPRECATION WARNING: Giving :session_key to SessionStore is deprecated, please
use :key instead. (called from new at app_root/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb:72)

Change :session_key to :key in environment.rb file :-

config.action_controller.session = {
:key => '_radar_session',
:secret => '271c2f352da72.....'
}


(2) DEPRECATION WARNING: config.load_paths is deprecated and removed in Rails 3, please use autoload_paths instead

Change in the environment.rb file :-

From config.load_paths to config.autoload_paths

(3) DEPRECATION WARNING: Date#last_month is deprecated and has been removed in Rails 3, please use Date#prev_month instead. (called from ./spec/models/my_model_name_spec.rb:10)

(4) DEPRECATION WARNING: Time#last_month is deprecated and has been removed in Rails 3, please use Time#prev_month instead. (called from ./spec/models/my_model_name_spec.rb:41)

Here are the actual changes in rails 2.3.9 :-
app_root\vendor\rails\activesupport\lib\active_support\core_ext\date\calculations.rb

(5) DEPRECATION WARNING: Rake tasks in vendor/plugins/xss_terminate/tasks are deprecated. Use lib/tasks instead. (called from app_root/vendor/rails/railties/lib/tasks/rails.rb:10)

Move the tasks folder inside the lib folder of the plugin directory and the deprecation warning should go away. But you may need to change some require file paths according to new placement of tasks folder.

(6) DEPRECATION WARNING: Object#returning has been deprecated in favor of Object#tap. (called from helper at app_root/vendor/gems/rspec-rails-1.3.0/lib/spec/rails/example/helper_example_group.rb:59)

I googled around for this deprecation warning and found some useful articles. Sharing one of those articles :-

Upgrading to Rails 3: Beware of the Object#tap pattern
http://feeds.simonecarletti.com/simonecarletti/en


I also tried with rspec-rails-1.3.2 gem, but it also threw same deprecation warning. So I just opened the corresponding class and extended the implementation as :-

From
@helper_object ||= returning HelperObject.new do |helper_object|

To
@helper_object ||= HelperObject.new.tap do |helper_object|

I made similar change for app_root\vendor\gems\rspec-rails-1.3.0\lib\spec\rails\mocks.rb :-

From
returning model_class.new do |model|

To
model_class.new.tap do |model|

Now, I am much closer to moving my app to Rails 3.0 version :-)

Tuesday, September 28, 2010

Migrating rails app from 2.2.2 to 2.3.5

I recently migrated my rails app from rails version 2.2.2 to 2.3.5. I enjoyed the work as it was a good learning for me. Listing the steps that I followed and some issues that I faced during the migration.

Gems installed on my windows machine :-

mongrel (1.1.5 x86-mingw32)
rake (0.8.7)
rack (1.0.1)
rubygems-update (1.3.7)


(1) I installed rails :-

gem install rails -v=2.3.5

(2) Deleted rails folder (2.2.2) from app/vendor.

environment.rb file -

RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION


Go to the project root and execute :-

rake rails:update --trace

It will update some js files and also renames application.rb to application_controller.rb

** Invoke rails:update (first_time)
** Invoke rails:update:scripts (first_time)
** Execute rails:update:scripts
** Invoke rails:update:javascripts (first_time)
** Execute rails:update:javascripts
** Invoke rails:update:configs (first_time)
** Execute rails:update:configs
** Invoke rails:update:application_controller (first_time)
** Execute rails:update:application_controller
app_root/app/controllers/application.rb has been renamed to app_root/app/controllers/application_controller.rb, update your SCM as necessary
** Execute rails:update

(3) Rename application_spec.rb to application_controller_spec.rb

(4) Localize rails version into the app.

rake rails:freeze:gems

(5) I was having rspec(1.2.3) and rspec-rails(1.2.3) plugins which I removed and installed rspec(1.3.0) and rspec-rails(1.3.0) gems instead and then localized in the app/vendor.

gem install rspec -v 1.3.0
gem install rspec-rails -v 1.3.0


environment.rb file :-

config.gem "rack", :version => "1.0.1"
config.gem "rspec-rails", :lib => false, :version => ">= 1.3.0"
config.gem "rspec", :lib => false, :version => ">= 1.3.0"


Go to the project root and execute :-
rake gems:unpack

(6) I kept a copy of my customized spec/spec_helper.rb file because I wanted to run "ruby script/generate rspec" for upgrading rspec-rails in the app which overwrites these three files :-

* spec/spec.opts
* spec/rcov.opts
* spec/spec_helper.rb

(7) While running the specs, I got flash.now[:message] specs failing.

I added following in the spec/spec_helper.rb file to fix the issue with that spec.

module DisableFlashSweeping
def sweep
end
end


module EnableFlashSweeping
def sweep
keys.each do |k|
unless @used[k]
use(k)
else
delete(k)
@used.delete(k)
end
end
# clean up after keys that could have been left over by calling reject! or shift on the flash
(@used.keys - keys).each{ |k| @used.delete(k) }
end
end


And I used the calls in the spec before the action as :-

it 'should retain the flash message only for the current request' do
controller.instance_eval { flash.extend(DisableFlashSweeping) }
post :create, :work_loc => {:country => "India", :state => "Maharashtra"}
response.should be_success
flash[:message].should == "Error in Loc mapping!"
end


(8)
I changed in rspec from

response.should render_template(:states) '
TO
controller.should_receive(:render).with(:partial => 'states')

(9) Changed response.headers["Status"] to response.status in some of the controller specs.

(10) I got one deprecation warning about formatted_url :-

DEPRECATION WARNING: formatted_action_name_controller_name_url() has been deprecated. Please pass format to the standard action_name_controller_name_url method instead..

So changed :action from
:action => formatted_action_name_controller_name_url('js')
to
:action => action_name_controller_name_url(:format => 'js')

Now, along with the rspecs, my app is looking good with rails 2.3.5

Planning to go ahead with migrating to 2.3.9 to make the app more closer to Rails 3.0.

Tuesday, September 21, 2010

The Last Lecture by Randy Pausch

Today I received an email from my uncle about The Last Lecture by Randy Pausch. I was wondering why I did not get this email from anyone else before as it seems a quite old email. It's ok ! The important thing is I got a chance to read Randy's simple but succinct view points about life. I can not resist myself to share those with all.
----
On September 18, 2007, Carnegie Mellon professor and alumnus Randy Pausch delivered a one-of-a-kind last lecture that made the world stop and pay attention. It became an Internet sensation viewed by millions, an international media story, and a best-selling book "The Last Lecture" that has been published in 35 languages. To this day, people everywhere continue to talk about Randy, share his message and put his life lessons into action in their own lives.

In a letter to his wife Jai and his children, Dylan, Logan , and Chloe, he wrote this beautiful "guide to a better life" for his wife and children to follow. May you be blessed by his insight.

POINTS ON HOW TO IMPROVE YOUR LIFE

Personality:
1. Don't compare your life to others'. You have no idea what their journey is all about.
2. Don't have negative thoughts of things you cannot control. Instead invest your energy in the positive present moment
3. Don't over do; keep your limits
4. Don't take yourself so seriously; no one else does
5. Don't waste your precious energy on gossip
6. Dream more while you are awake
7. Envy is a waste of time. You already have all you need..
8. Forget issues of the past. Don't remind your partner of his/her mistakes of the past. That will ruin your present happiness.
9. Life is too short to waste time hating anyone. Don't hate others.
10. Make peace with your past so it won't spoil the present
11. No one is in charge of your happiness except you
12. Realize that life is a school and you are here to learn.
Problems are simply part of the curriculum that appear and fade away like algebra class but the lessons you learn will last a lifetime.
13. Smile and laugh more
14. You don't have to win every argument. Agree to disagree.

Community:
15. Call your family often
16. Each day give something good to others
17. Forgive everyone for everything
18. Spend time with people over the age of 70 & under the age of 6
19. Try to make at least three people smile each day
20. What other people think of you is none of your business
21. Your job will not take care of you when you are sick. Your family and friends will. Stay in touch.

Life:
22. Put GOD first in anything and everything that you think, say and do.
23. GOD heals everything
24. Do the right things
25. However good or bad a situation is, it will change
26. No matter how you feel, get up, dress up and show up
27. The best is yet to come
28. Get rid of anything that isn't useful, beautiful or joyful
29. When you’re awake alive in the morning, thank GOD for it
30. If you know GOD you will always be happy. So, be happy.

Here is the video link as well :-
http://video.google.com/videoplay?docid=-5700431505846055184#

Sunday, August 1, 2010

Beautiful nature snaps...

Last week, I captured some beautiful nature snaps near Kolhapur, Maharashtra. Sharing few of those snaps ...







Thursday, July 22, 2010

Hasgat - A book by Dilip Prabhawalkar

Yesterday, my father gave a marathi book - 'Hasgat' to me. It is written by a well known and my favorite marathi actor Dilip Prabhawalkar. I could not resist myself to read his book. The book made my travel to office and back to home journey jovial.

The book is a collection of short stories which can be enjoyed any time. The common thread that binds these stories is the element of situational humour and the naive characters in each of these, reminiscent of the P.G. Wodehousian style, which has admittedly been one of Prabhawalkar's literary influences.

Dilip Prabhawalkar has done a great work in theatre, cinema, television and as a writer as well. Please take a look at his website :- http://dilipprabhavalkar.com/v1/indexHtml.htm

I have watched his drama - 'Hasvaphasvi' at least 8 to 10 times. You can see the pictures of six different character roles that he played in that drama at : http://dilipprabhavalkar.com/v1/hasvaphasvi.htm

Isn't it awesome ? :-)

Enjoy reading ...

Tuesday, July 6, 2010

Augmented Array in Ruby

Few days ago, I was randomly going through the Ruby Array class API and the method '*' caught my attention.

array * int -> an_array : Returns a new array built by concatenating the int copies of self.

[ 1, 2, 3 ] * 3 #=> [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]

I just had a thought can I have a method named '/' which will return a new array by splitting the array into arrays of int divisor elements each ?

The functionality that I was looking for :-

[1,2,3,4,5,6]/1 # => [[1], [2], [3], [4], [5], [6]]
[1,2,3,4,5,6]/2 # => [[1, 2], [3, 4], [5, 6]]
[1,2,3,4,5,6]/3 # => [[1, 2, 3], [4, 5, 6]]

I gave it a try, my fingers typed the code as per my brain's instructions and it worked the way I expected.

Then I saw the methods at(index) and fetch(index) and thought can I fetch or even set the elements of the array with the index as if index acting as array's attributes ?

Like this :-

ary = [1,2,3]
ary._0 = 25
ary._0 # => 25
ary._1 = 10
ary._1 # => 10
ary # => [25, 10,3]

For the above to work, I played with the method_missing method.

Few things that I noticed in the Array class were it has 'first' and 'last' methods but not 'first=' and 'last=' methods. It has 'nitems' method which returns the number of non-nil elements, but no 'nilitems' method which will return nil elements in the array.

My mind started to think whether I can build some other useful methods as well and it came to a sufficiently big list which I finally moved into a gem. I named the gem as 'augmented_array' and pushed it to gemcutter.

Install:
====
gem install augmented_array

Uninstall:
====
gem uninstall augmented_array

Source Code is available at my Github repository.

Thursday, July 1, 2010

The One Minute Manager

Yesterday I read a management book - 'The One Minute Manager' written by Ken Blanchard and Spencer Johnson. I liked that book very much. It's practical. It includes some examples demonstrating how you can effectively handle the people under you. By the book definition, effective managers manage themselves and the people they work with so that both the organization and the people profit from their presence.

The metaphor, The One Minute Manager means it takes very little time for that manager to get big results from people and behind this success lie just three secrets :-

- One minute goals
- One minute praisings
- One minute reprimands

One should read this little book to know more about these secrets.
It is really good to know that the leaders of American and Japanese industry have made this book compulsory reading for all their managers.

Enjoy reading ...

Thursday, June 24, 2010

Some good food of thoughts

I started my day today with reading my colleague's beautiful post what mindfood are we eating and it really made me think.

This is such a wonderful thought... what do we feed our mind with ? How many of us make conscious efforts to nurture our mind ? Hmm ... need to prepare healthy diet plan for our minds as well :-)

Sharing some good food of thoughts that I got from googling :-

1. Success is not the key to happiness. But happiness is the key to success.
2. You can tell whether a man is intelligent by his answers. But you can tell a man is wise by his questions.
3. Morning means one more inning given by the god to play.
4. Success is not a matter of being the best and winning the race, it is a matter of handling the worst and finishing the race. Be positive.
5. A honey bee visits 2 million flowers to collect 500 mg of honey. So our workload is nothing as compared to them. Be cheerful and keep working.
6. It is not that some people have will power and some do not. It is that some people are ready to change and others are not. Believe in yourself and change for betterment.
7. The world suffers a lot, not because of the violence of bad people, but because of the silence of good people.

Wednesday, June 23, 2010

Tips for Managers

I have worked with a couple of good companies. The managerial behavioral pattern that I have observed across these companies remains more or less the same. Yes... there are certainly few exceptions. I have many friends across different organizations, but to be frank, I have rarely seen people talking good about their managers. Why is this so ? Are the managers lacking the skills to effectively handle the people under them ? Or some other reason ? There is no straightforward answer to these questions, but can we improve this better ? I am not at manager level yet, but certainly I can suggest few tips which would improve this situation.

Tips for Managers :-

1. Consider people under you as people rather than only billable resources.

2. Do not let people under you to lose trust in you. It is very difficult to build back the trust again.

3. Give more importance to career progression of the people under you than billing.

4. Have faith in your people.

5. You do not have any right to play with or spoil the career of the people under you. Freshers are the best example of this. They are rarely asked about their career aspiration, rather they are asked to do things what the current situation demands.

6. Do not take people under you for granted.

7.
Interact with your people regularly about their aspirations and make loyal efforts to fulfill those.

8. A little smile on your face makes a huge difference in the professional and personal lives of the people under you. The most important thing here is that it's absolutely free of cost.

9. Try to be a role model of the people under you.

10. Billing/Revenue is important. But people are more important as they sustain business with the client by their good work.

11. Micromanagement kills.

12. Try to be a thought leader than just to be a manager.

13. Do not lose your core values while dealing with the client.

Friday, June 18, 2010

Welcome Monsoon !

The monsoon has started in Mumbai - Maharashtra with full force and one of my friends forwarded some great nature pictures especially from Konkan region to me. I can not resist myself to share some of those beautiful photos with you all.

Marleshwar waterfall near Sangameshwar in Ratnagiri district:



Jog waterfall:



A typical home in Konkan:



River bank:




Happy monsoon ! :-)
It's real time to go for a trek / nature trail !