Archive for the ‘Technical Articles’ Category

February 4th, 2011

Configure Sphinx in Rails application

Contributor : Nagendra



Install Sphinx

Just run the following three commands on your server or dev machine to install Sphinx:

./configure make sudo make install

That will setup Sphinx with default for use with MySQL. If you want to use it with PostgreSQL, then run configure with the following flag:

./configure --with-pgsql

Note: you can download the sphinx from http://sphinxsearch.com/downloads/beta/

Install Thinking Sphinx

Even though there are a couple of Sphinx plugins for Rails, I chose to go with Thinking Sphinx, as it seems to be the most popular and feature complete.
So you can install it as a Rails plugin using
script/plugin install command:

script/plugin install git://github.com/freelancing-god/thinking-sphinx.git

Writing code to use sphinx search:

We now need to index our models. This consists of adding a few small lines of code into each model that you want to be able to search. So lets say we have a Blog app (doesn’t everyone!), which has a Post model. And that Post model contains the usual title and description fields. We therefore add the following bit of code beneath our association declarations in

app/models/post.rb:
define_index do indexes title, description end

Those very short three lines will tell Thinking Sphinx to index the title and description fields of the Post model, and allow us to search through all our posts. Now we just need to index and start Sphinx. And Thinking Sphinx makes this very easy with it’s handy Rake tasks.

Just run this:

rake ts:rebuild

That will stop (if it is started), index and start Sphinx for you. Now we need to create a quick search form. This will eventually be a global site search, and not just a Post search. So we will create a new controller:

script/generate controller search

Then create a view at app/views/search/index.html.erb and place the form within it:

Now in your new Search controller, create a new create action:

def create @posts = Post.search params[:search] end

Create your create view at app/views/search/create.html.erb with a bit of code to display your @posts in the usual way.

Note:

We can even paginate our results using the WillPaginate plugin:

def create

@posts = Post.search params[:search], :page => params[:page], :per_page => 10 end



February 1st, 2011

How to Install Ruby on rails in your system

Contributor : Nagendra


Do following steps to setup rails environment in the local system

1) CSV : Git and Subversion

sudo aptitude install subversion
 sudo apt-get install git-core
And you can also installed the suggested package 
: git-doc git-arch git-cvs git-svn git-email 
git-daemon-run git-gui gitk gitweb diff-doc.
1) Database setup:
Mysql database:  sudo aptitude install mysql-server mysql-client
PostgresSQL:
 sudo apt-get install postgresql postgresql-client postgresql-contrib
 sudo apt-get install pgadmin3
 sudo apt-get install libpq-dev
refer link  http://hocuspokus.net/2007/11/install-postgresql-on-ubuntu-710
3) Development IDE : Netbeans
  First download the latest version for Ruby on
 http://www.netbeans.org/ and install it with sh.
  You need Java to run Netbeans
from command prompt type:
sudo sh ./netbeans.sh (path where your netbeans exists))
1) Now lets install Ruby on Rails:
in the Terminal (Applications -> Accessories -> Terminal)
key in the following commands

#sudo su
#apt-get install build-essential
#apt-get install ruby rdoc libopenssl-ruby
#wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
#tar zxvf rubygems-1.3.7.tgz
#cd rubygems-1.3.7
#ruby setup.rb
#ln -s /usr/bin/gem1.8 /usr/local/bin/gem
#gem install rails -v 2.3.8

This should install rails 2.3.8 version.

Now we can install desired gems for the databases we use either postgres or mysql:
MySQL gem:
   sudo gem install mysql
Postgres gem:
sudo gem install postgres-pr
sudo gem install postgres
Thats it this should be able help you install rails development environment.
May 11th, 2010

Ruby enterprise edition + Passenger installation

Contributor : Vinayan

Ruby enterprise edition can be installed on the server using the following steps :

$ wget http://rubyforge.org/frs/download.php/68719/ruby-enterprise-1.8.7-2010.01.tar.gz

$ tar -zxvf ruby-enterprise-1.8.7-2010.01.tar.gz
PS: Make sure that the patch is installed on the server. If it doesn’t exist then install it via yum.

$ yum install patch

$ ./ruby-enterprise-1.8.7-2010.01/installer

Once the ruby enterprise edition is installed , the following message will appear :

“Ruby Enterprise Edition is successfully installed!”

May 8th, 2010

Capistrano deployment with subversion

Contributor : Vinayan

Capistrano Deployment

Capistrano is a tool used for automation of the application deployment process. Capistrano is mainly used for deploying rails apps. Changes made to the rails app can be easily transferred to the server using cap deploying. Capistrano can be configured with any version control system like SVN / GIT for deploying an app. Also, we can define application server type (mongrel, mod_rails / Fcgi) on which the app has be deployed in Capistrano. Here I’m going to discuss cap deploying an app using SVN with Mongrel cluster as the application server.

March 8th, 2010

Welcome Rails 3.0

As of December 23, 2008, the Merb (Mongrel + Erb) project is being merged with Rails, and a version with the best features of both will be released in 2010 under the name Rails 3.

Main additions in Rails 3.0

- Brand new router with an emphasis on RESTful declarations
- New Action Mailer API modeled after Action Controller
- New Active Record chainable query language built on top of relational algebra
- Unobtrusive Javascript helpers with drivers for Prototype and jQuery

Get Adobe Flash playerPlugin by wpburn.com wordpress themes