Archive for Uncategorized

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)

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)

Creating value…

i really didn’t write anything here from very long time.. i can give list of causes but who cares.. !!

So today , i was talking to some of my old friends , at Cafe Durga near BVP, and we started discussing about the entrepreneurship..aha.. my favourite topic.

So Deepak was sharing his experience about the Innovative product that he tried to develop at his workshop.
He had develop some prototype small scale WindPower generate , his target customer is farmers. He and his dad was working on it and they have set the some target budget which the product should not cost beyond that.

After compition of the product in tight budget , they tested it by installing it on there workshop’s roof.. and result were not up to the mark. He mention some technical problem … which obviously i couldn’t get it because of my Only-Comp background.

So while discussing this , we talked about what should be priority of individual person should have … money or value.. ?

According to deepak , first and most important thing is that business or product should make money for its promoter or creator.. , but i was trying to explain him about how individual should first concentrate about the Value his product or business create to its customer/users… then after that money is obvious thing that is gonna follow. ( very much in the style of Guy Kawasaki )

of course couldn’t convince him..  because he don’t want to get convince with this as he was very frustrated with failure ..

May be next week i will give a look at his product.. ( even though he don’t want me too.. ) and wish that he would let me help him…

Comments (1)

Choosing AJAX framework?

Today I meet my Project guide. One more meeting where he was throwing all bouncers. I hardly understand what he said. But i manage to get answer to my questions at least.

I will write about my project after some time, as i really need to make sure that what i am writing here i should implement that. Project is in very early stage of design, implementation is very long journey, though i would say we had good start and comparativly good resources available.

So as Guide said we may be need to use AJAX for Our Dashboard module. He gave us just one option , but i started thinking if i am going to use AJAX then what framework i should choose? yes that was the same question to him also. He recommended Dojo(http://dojotoolkit.org/), even i dont heard about it before , i am aware of mooTools(http://mootools.net/) though. I am not that much familiar with AJAX or JavaScript.

Comments (2)

Follow

Get every new post delivered to your Inbox.