rails 3.1 Reversible Migrations

Migrations has been always one of the importnat features of Rails. With Rails 3.1 they got new , it no more up and down methods , there is only one method change .

if you look at any migration , there are couple of questions like “why class methods ?” , “why rails not taking care of reversing migration itself?”

this is what new approach is all about !

Aaron Patterson  simplified things !

The new Change method !

<code>

class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :title
t.text :description
t.string :image_url
t.decimal :price

t.timestamps
end
end
end

</code>

this is default migration for Models using change method , as you can see there is only up logic . When you want to do rollback , rails will figure out how to reverse the migration from understanding your up code .

But ofcource there are few things which cannot be automatically reversed , this is becuase inforamtion required to do so is not available. e.g remove_column . In such cases rails will rais exception “ActiveRecord::IrreversibleMigration" .

In this case manually define up and down method . but then it can be just simple instance methods and not class methods .

Do take a look at the code  to understand what is happening .

Leave a Comment

Marshaling Objects – Ruby

Ruby can take an object and convert it into stream of bytes that can be stored in database or can exposed outside of application. This is almost similer to Object Serialisation , which is very comman in java. In ruby , same process is called marshaling .

But there are two things need to be considered .

1. Some Objects cannot be dumped , if the objects to be dumped include bindings , procedure or methods objects , instance of class IO, singleton Object , or if you try to dump non-name classes or modules . (It will raise TypeError )

2. When you load marshaled object, Ruby needs to know the defination of class of that object.

very Common use case of Rails using marshaling is to store session data.

Leave a Comment

reset – Rails !

I have finally started going through Rails again, it’s been a while since I have put my hands on code. Even Rails has moved on from 2.3.5 to 3.1.3, but it left me behindJ.

At Webonise , we do have some passionate guys who have been coding religiously on Rails form last 2 years and they know way more than what I used to know at one point in time.  But, trust me, I still have strong base and things are very easy for me to learn as I have spent around 3 years churning out ruby code day and night. So my team can expect some competition soon!

To start off with, I have started with Agile Web Development with rails again. This is probably the first book which I refereed when I started 4 years back!

Progress… On page 66 now, hoping to finish 470 pages by Sunday (as long weekend coming on the way ). Wish me luck!

 

 

Leave a Comment

Mysql issue on Mac OS X

I was setting up my rails evironment after long time and did some update to stack with mac os x update itself. Faced with small issue when tried to run rake db:create

rake aborted! uninitialized constant Mysql

I just have to fix it with change in gemfile , as it mentioned default sqlite3 gem , just add mysql gem in gemfile and it would be fixed . (note : do run bundle install )

Comments (1)

Start and Stop MySql in Mac Os X 10.6 Snow Leopard

If you want to start MySql in Leopard, you need to call the startup item directly from the command line:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

And to Stop MySql

sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop

You can also make alise into your bash_profile file !

alias start_mysql="/Library/StartupItems/MySQLCOM/MySQLCOM start"
alias stop_mysql="/Library/StartupItems/MySQLCOM/MySQLCOM stop"

Leave a Comment

BarCamp Pune 6

Barcamp Pune 6 is again in town this Saturday i.e 14th Nov 2009.

For all those who are not aware of the BarCamp , Navin Kabra of PuneTech.com has written two amzing blog post about barcamp here “What is Barcamp?” and if you are student then “Why should student attend barcamp?

Will update this post with the coverage from Barcamp tomorrow.

 

Comments (1)

Slumdog Millionaire and Its Criticism

personally i loved the movie Slumdog Millionaire, But i dont understand why its getting such criticisam from indian schoolers.

One of the writer Sudip Mazumdar of Newsweek wrote:

“People keep praising the film’s ‘realistic’ depiction of slum life in India. But it’s no such thing. Slum life is a cage. It robs you of confidence in the face of the rich and the advantaged. It steals your pride, deadens your ambition, limits your imagination and psychologically cripples you whenever you step outside the comfort zone of your own neighborhood. Most people in the slums never achieve a fairy-tale ending.”  Link

These are very disturbing remarks. Auther has compared his story with Slumdog millionaire and try to create a picture that people from slum dont go anywhere. Then how come he writing for Newsweek?

Yes,slum still your pride , but it also gives you ability to understand what is real pride is!

Yes, slum deadens your ambition, but it help you to set some realistic ambitions!

yes, Its limits your imaginations, But its also you to understand what is the real problem and ability to answer those in most effective way!

No , Slums dont cripples you , Rather slum always remind you that there are so many things that need to be changed in your neighborhood whenever you steps outside.

Most people in the slums never achieve a fairy-tale ending , Yes. But they atleast make sure next generation leaves better life than they have lived.

Comments (2)

Older Posts »
Follow

Get every new post delivered to your Inbox.