August
25
2010

Upgrade Rails Performance

In this article, we will try to Enhance our rails application performance.

August
17
2010

Joins in SQL

Sometimes, its very hard to keep Joins concept in mind.. Being a beginner, experienced SQL programmer, you should know the concept of JOINS.

In this article, I will show you the difference between:
1. JOINS and INCLUDE
2. How to you use JOINS in rails
3. JOINS over INCLUDE

August
17
2010

Send Tweets from Rails Application

So, we’re continuing from here: http://puneetitengineer.wordpress.com/2009/08/12/send-tweets-fr…ls-application/

So far we’ve covered the basics of it, now its time to create some controllers…. Open your command/terminal and fire this command:

ruby script/generate controller twitt

Once you’re done, open this file and write the below code inside it:

class TwittController < ApplicationController

gem(‘twitter4r’, ‘>=0.2.0′)
require ‘twitter’
require ‘twitter_search’
require ‘rubygems’
before_filter :authorize, :except => [:login, :authenticate, :save_users, :twitter_cred]

def login
@user = User.new
end

def authenticate

@user = User.new(params[:user])
client = Twitter::Client.new
if client.authenticate?(@user.username, @user.password)
@username = User.save_users(params[:user])
session[:user_id] = @user.id
session[:username] = @user.username
session[:password] = @user.password
redirect_to :action =>’post_status’
else
render :action =>’login’
end

end

end

Now, open /app/views/twitt/login.html.erb and paste below lines:

<% form_for :user, :url => { :action => :authenticate } do |form| %>

<%= label :user, :username, "UserName:" %>
<%= form.text_field :username, :size => 30 %>

<%= label :user, :password, "Password:" %>
<%= form.password_field :password, :size => 30 %>

<%= submit_tag "login" , :class => “submit” %>
<% end %>

June
18
2010

Integrate Oracle with Ruby

Since most of the rails application is now using various databases, this article will show you how you can use ORACLE database with rails.

For that, we need Oracle XE

June
18
2010

Integrating Cucumber & Rpsec with Rails

Hi Guys,

In this article I will cover how to use cucumber and Factory Girl to write Stories in Rails.
TDD(Test Driven Development) is the most powerful and most approachable concept in most of the programming language. When it comes to rails, it provides a convenient and simplest way to write Unit test cases and the stories for your controller, without writing complex lines of code.
Let’s see how you can cover the test coverage for your rails application.
IMPORTANT: The concept behind using cucumber, so that we can write the ‘stories’, which will tell us how our controller’s method behaves when its called.
To get started, install the cucumber gem on your machine by typing:
gem install cucumber
and you’ll find progress like this:

Next, you need to install rspec and rspec-rails. To do that type:
gem install rspec
gem install rspec-rails

May
19
2010

What is Mongo-DB

What is MongoDB?
I saw many forums, visited many blogs, people/programmers are talking about MongoDB a lot. I was wondering what this is! Why developers are showing more and more interest in this. I started searching around and now sharing with all of you, who are not friendly with MongoDB or who’re familiar but don’t know how to work on it.

First of all let’s define mongoDB in terms of technical aspect
a) MongoDB has collections of data, not tables.
b) Its a document-oriented database.
c) MongoDB has namespaces for data.
d) You don’t ever need to worry about migrations due to Mongo’s schema-less nature.
e) You can define indexing options too.

So far, what my learning works here that it has nothing to do with the migrations, tables. In short if I say, it is a database in a documented form, a separate entity as compared to MySQL or different databases, am I wrong?

Ok, try to put your brain to understand this, because from here I will try to cover some real world examples to explain how it works… :)

How to install MongoDB
A) gem install mongo
It will install mongo with bson.. something like this screenshot

B) gem install mongo_mapper

I think, these two gems are sufficient to give you some kind of acceleration. Let’s proceed further and create a model, fire this command
C) ruby script/generate model Book –skip-migration

D) Let’s enter some fields into it, as I said it has nothing to do with the migration, so what are the columns that we want, we will create here itself, See how:

April
21
2010

Rails 3, Its here!!

In these days lots of people are talking about RAILS 3, the biggest and most happening version as compared with the previous ones. There are many changes in each and every part of the application.

Here, we will cover the changes, dependencies, how we install rails 3 on windows and linux and a basic sample RAILS 3 application..

So Here we go:
1st We will install rails 3 on windows.
Note: To Install rails 3, you must be having ruby-1.8.7 or higher, So If you’re running with ruby-1.8.6, it’s time to upgrade now.
To do that download the executable version of ruby(either 1.8.7 or 1.9.1) click here and download Ruby 1.9.1-p378 (RC2). Once done run the setup and check both the option as per the below image.

Once done with the installation, You need to copy 3 DLL files under /Ruby19/bin folder and these files are:
1. readline.dll (Download from here)
2. ssleay32.dll (Download from here)
3. zlib.dll (Download from here)
4. OpenSSL(Download from Here)
For better examples, you can also refer UKNatureBlog

Once you copied all the dependencies, now it’s time to start few gems, which will help us to install rails 3.0.
Do update your system with this:
gem update –system
Because bundler and i18n looks for rubygem >= 1.3.6
To install these gems, open up command prompt and type:
gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n

and you’ll find progress something like this:

You have to install rack as well in order to install rails 3. To do that type:
gem install rack
Once done with it, now its time to install rails 3.0, so do this:
gem install rails –pre

Note: Don’t worry if your installation fails somewhere in the middle. Important is your gems(like activerecord, activeresource etc.) should be installed successfully, no matter ri and rdoc encounters an error.

So far we’ve installed ruby-1.9 and rails-3.0. Now it’s time to create your first rails application. Here I am assuming that you already have mysql installed in your system. So open up your command prompt and fire this command.
rails myrails3_app -J -d mysql
and you’ll see progress like this:

Other possible parameters:
1. –skip-activerecord

Now let’s look at the directory structure which rails-3.0 has created for us:

At first glance you will notice that, there is no change in the directory structure, everything is the same. Magic take place once you start working on it.. So let’s play around with some code and see the differences..
Let’s generate scaffold:

ruby script/generate scaffold User name:string email:string dob:integer twitter:string