Archive for the ‘Technical Articles’ Category

March 7th, 2012

Problems faced while setting up Rails 3 with ruby-1.9.2

I migrated all my applications to Rails 3 with ruby 1.9.2,  After I installed ruby I faced few errors. Few of them are
1) The arrow keys were not working in irb console and “no such file to load –readline” error.
This is the problem which occurs when the readline extension is not installed with ruby source. All you have to do to fix this error is,
Go to your ruby source folder you downloaded and installed ruby from.
1.  cd  ~/ruby-1.9.2 2.  cd  ext/readline
and execute the commands below.
3. ruby  extconf.rb 4. make 5. sudo make install
If you find any errors while executing ruby extconf.rb showing ..no for each checkings. Then you need to install these two libraries on your system
sudo apt-get install libncurses5-dev libreadline5-dev
then later execute the commands starting from 3.
2) The other error was after I create application and start the server, the error was “no such file to load –openssl”
Again it was the error with openssl ruby extension not installed with ruby, you can fix this error by executing the following commands.
Go to the ruby source file
1. cd  ~/ruby-1.9.2 2. cd  ext/openssl
and execute the commands below. 3. ruby extconf.rb 4. make 5. sudo make install
If you find any errors while executing the command ruby extconf.rb showing ..no for each checkings, then you need to install the package in your system
sudo apt-get install openssl libopenssl-ruby libssl-dev
then later execute the commands starting from 3.
Similarly I found may other files which were causing errors since the extensions were not installed like zlib etc..
If you find ‘no such file to load error ‘ for any of the extensions, then you need to go to ruby source folder. Go to respective directory inside ext/ (eg: readline/ for ‘no such file to load –readline’) and execute the following commands inside that folder
ruby extconf.rb make sudo make install
If you cannot successfully execute ruby extconf.rb, then you need to install respective libraries and execute these commands above again.
Note: I work on ubuntu operating system, If you face same errors in centos or any servers which I faced on a server with CentOS where you don’t have apt-get or aptitude installer, you need to search for particular package with yum search and install the package compatible with your operating system. Hope this helps.

——————————————

Install Rails3 on Ubuntu system with Rails 2.X.X in the system.

I was working on Rails 2.x.x and all I did to catch Rails3 was removed the old Ruby library, un-installed Rails and gems and installed a latest Ruby library which supports Rails3. The commands I executed to remove the Ruby library were
# sudo gem uninstall rails
This will uninstall the Rails in your Ubuntu system
# sudo apt-get purge ruby rubygems 
This will purge the Ruby library and all gems installed in your system.
After un-installing I installed Ruby-1.9.2 by following commands
# wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
# tar -xvvf ruby-1.9.2-p0.tar.gz
# cd ruby-1.9.2
# ./configure
# make
# sudo make install
It was just installation of this Ruby library, it got me the irb and gem installed in my system since all Ruby libraries with 1.9.X versions has irb and gem inbuilt unlike old Ruby versions where we had to install irb and gem manually.
I installed Rails3 with following command
# sudo gem install rails –version 3.0.0 # sudo bundle install      // This installs all the supportive bundles required.
This got me Rails3 installed in my system, and creation of project and running the application server is little different compared to Rails 2.x.x .
Creating sample application using Rails3 with scaffolding
->     rails new application_name -d mysql ->     rails generate scaffold Post title:string body:text ->     rake db:create   ->     rake db:migrate ->     rails server
I got the welcome page of Rails3 app.
March 3rd, 2011

How to Set up Redmine-project tracking system

Installation Steps

1) Make sure ruby 1.8.7 and Rubygem are installed

2) Install Rails and few required gems

gem install rails -v=2.3.5
gem install rack -v=1.0.1
gem install -v=0.4.2 i18n

3) Checkout the Redmine source code

svn co http://redmine.rubyforge.org/svn/branches/1.0-stable redmine-1.0

4) Go to redmine-1.0/config and rename few files

mv database.yml.example database.yml
mv email.yml.example email.yml

and do the database and email configuration

5) Run rake db:create to create database. then run database migrations using rake db:migrate

It will create tables and an administrator account.
If you get this error:

Rake aborted!
no such file to load — net/https

you need to install libopenssl-ruby1.8, in ubuntu, just like this: apt-get install libopenssl-ruby1.8

6) Generate a session store secret.

rake generate_session_store

7) Insert default configuration data in database, by running the following command:

rake redmine:load_default_data

This step is optional but highly recommended, as you can define your own configuration from scratch. It will load default roles, trackers, statuses, workflows and enumerations.

8 ) Setup is complete. Start the server

ruby script/server

9) Use default administrator account to log in:

login: admin
password: admin

For more information visit http://www.redmine.org/wiki/1/RedmineInstall

February 10th, 2011

Group chat room in Rails

Contributor : Nagendra

Introduction:
Chat Engine is a lightweight rails engine that heavily uses jQuery and memcached to implement a very simple group chat room.

Features:

* You must enter a nickname to be part of the chat room.
* All logged in users are shown in the user list
* Lines in the chat that mention a users nickname are highlighted.
* Inactivity timer will logout users from the client side.
* rake task to logout users whose browsers do not allow ajax requests in the unload event.
* The ability to mute specific users (from script/console). Muted users will see their own messages, but no one else will.


Implementation:

install chat-engine

./script/plugin install git://github.com/amiel/chat-engine.git

copy assets

rake chat:sync

include assets, don’t forget jquery

<%= stylesheet_link_tag 'chat' %>
<%= javascript_include_tag 'jquery-x.x.x.js', 'auto_scroll', 'chat' %>

use the chat_overlay partial

<%= render :partial => 'chats/chat_overlay' %>

Note: make sure you have Jrails installed and the prototypes are properly included.

February 9th, 2011

File Uploading using Paper clip Rails Plugin

Contributor : Nagendra


This is one of the most useful plug in that can be used in your application when you require to upload a file as attachment to your application, its quite easy to use and with the help of paperclip scaffolding you can achieve file upload feature very easily, below i have explained the steps to create a simple application using scaffolding that enables the file upload feature with the help of paperclip plugin.


Steps:
Install the required gems to run the paperclip plugin from the below mentioned command,

$ gem sources -a http://gemcutter.org
http://gemcutter.org added to sources
$ sudo gem install view_mapper
Successfully installed view_mapper-0.2.0
1 gem installed Installing ri documentation for view_mapper-0.2.0...
Installing RDoc documentation for view_mapper-0.2.0...

1. First you need to create a rails app and change the database.yml setting and set things to install the plug in $rails student -d mysql

2 Then you have to just install the paperclip plugin into your application from the below mentioned command,

$ ./script/plugin install git://github.com/thoughtbot/paperclip.git

3. Once the plugin is installed, let me show you to create a simple scaffold with paperclip file attachment feature in it.
Just create a simple scaffold and check it out,

$ ./script/generate scaffold_for_view Student name:string branch:string comment:string --view paperclip:photo

Then you need to enter $ rake db:create and $ rake db:migrate
This will create the paperclip file attachment feature, just run $ script/server and check it out. The display looks just like the image i have mentioned at the beginning.

February 8th, 2011

Install Image-magick and rmagick for rails

Contributor : Nagendra


Start by removing any old versions previously installed via apt-get:

sudo apt-get remove imagemagick

Then update apt-get and install some supporting packages:

sudo apt-get update


*(sudo apt-get install
libperl-dev gcc libjpeg62-dev libbz2-dev
libtiff4-dev libwmf-dev libz-dev libpng12-dev
libx11-dev libxt-dev libxext-dev libxml2-dev
libfreetype6-dev liblcms1-dev libexif-dev perl
libjasper-dev libltdl3-dev graphviz gs-gpl pkg-config)*


*its a single line command.

get the Imagemagick package from this link:

http://www.imagemagick.org/script/install-source.php#unix

Once the source is downloaded, uncompress it:

tar -xzf ImageMagick.tar.gz


Now configure and make:

cd ImageMagick-6.5.0-0
./configure
sudo make
sudo make install


Add the following line to ~/.bashrc:

export LD_LIBRARY_PATH=/usr/local/lib

Update: If you still get an error like the one above, try running ldconfig:

sudo ldconfig

You can confirm the install and available formats with:

identify -list format

Once Image magick is installed install rmagick gem by typing the command:

$sudo gem install rmagick

Get Adobe Flash playerPlugin by wpburn.com wordpress themes