How to Install Ruby on rails in your system


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
.

2) 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))

4) 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.

Source: Railscarma

How to Setup Redmine Project Tracking System


Installation Procedure

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

Source: Railscarma

Remove files from the revision history of SVN repository


When we work on a private repository which is used for our personal testing or development, we may upload some private data. The unwanted file uploads in multiple commits will drastically increase the repository size. Once the development work is over and when we decide to make the repository public, we will have to consider removing the private data committed to repository in the development phase.

We can easily remove it from the application at our development machine and give a commit to the repository. But the data still remains in the previous commits. Here we have to find a solution for removing the files from revision history. If we get a fine method to do this, we can also help our customers with their repository quota management, also other Application Maintenance and Support.

I have done some testing with the ‘svndumpfilter’ option and could succeed to find a solution for removing files from the revision history of SVN repository. If anyone face an issue with svn repository over quota or interested in removing unwanted files from the history, you can follow the steps given below:

1. Take a dump of your repository.

     svnadmin dump /var/svn/REPOSITORY > dumpfile

2. Filter the dump file.

     svndumpfilter exclude /path/of/file/to/remove < dumpfile > newdumpfile

This will remove the file “/path/of/file/to/remove”. You can remove multiple files at a time like this:

     svndumpfilter exclude file1 file2 < dumpfile > newdumpfile

3. Create a new repository.

     svnadmin create /var/svn/REPOSITORY_NEW

4. Import the dumpfile in the new repository.

     svnadmin load /var/svn/REPOSITORY_NEW < newdumpfile

5. Replace the old repository with the new one.

    mv /var/svn/REPOSITORY /var/svn/REPOSITORY_OLD

    mv /var/svn/REPOSITORY_NEW /var/svn/REPOSITORY

To check this, browse your history and see one of the files you removed, you will get an error that the file could not be found. You might need to make a fresh checkout and a commit to see whether everything works as expected. If everything works fine, we can remove the dump files and old repository backup.

Source: Railscarma

File Uploading using Paperclip Rails Plugin


This is one of the most useful plugin 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.

Source: Railscarma.com

Capistrano Deployment with Subversion


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.

Installation:

Capistrano can be installed as a ruby gem as shown below:

$ gem install capistrano


Configuring a rails app to use capistrano:

This can be done by executing the following command from the rails app:

$ capify .

The above command will create a Capfile and config/deploy.rb file.

user@hostname [~/railsapp]$ capify .
[add] writing ‘./Capfile’
[add] writing ‘./config/deploy.rb’

user@hostname [~/railsapp]$ cat Capfile

load ‘deploy’ if respond_to?(:namespace) # cap2 differentiator
Dir[‘vendor/plugins/*/recipes/*.rb’].each { |plugin| load(plugin) }

load ‘config/deploy’ # remove this line to skip loading any of the default tasks

user@hostname [~/railsapp]$ cat config/deploy.rb

set :application, “set your application name here”
set :repository, “set your repository location here”

# If you aren’t deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
# set :deploy_to, “/var/www/#{application}”

# If you aren’t using Subversion to manage your source code, specify
# your SCM below:
# set :scm, :subversion

role :app, “your app-server here”
role :web, “your web-server here”
role :db, “your db-server here”, :primary => true


PS: As an alternative, we can directly create Capfile and deploy.rb file under the rails app and load necessary data to it using ‘vi’ editor.

Read More: Capistrano Deployment with Subversion

How to Integrate Paypal into Rails Application?


Paypal is an e-commerce based web application, which transfers the amount between two accounts. Almost all US-based companies use Paypal for receiving and doing their payments.

Lets see how to integrate this service in rails application in different steps.

Note: I have tried these steps in development mode, on my local machine. It works fine but haven’t tested in production.

Step 1

a> In case if one doesn’t have a paypal account, go to http://developer.paypal.com and sign up to make an account. Then login using that account.

b> In order to test the application user should have test accounts on paypal.

For example, I made two accounts, one as buyer and another as seller. Both have there secure login and later they can use these accounts to send or receive payments.

c> These pre-configured accounts can be created by going to test accounts tab. Then click on pre-configured option to create test accounts on paypal with little extra information. Please make note of the account id and password generated for both buyer and seller.

d> Now based on requirement check the checkbox of the particular account and click on the link box to enter that particular test account. Clicking on that will redirect you to http://sandbox.paypal.com. Using your account information you one can login to that particular account. These accounts and payments are simulated as any original account will behave.

e> Now lets code our rails application to use these accounts. I am using “Add to cart” option to select few items and add them into cart, by clicking on checkout button, it redirects to paypal site.On next page:-

f> In my cart.rb,paypal_url method to redirect to paypal site:
def paypal_url(return_url,notify_url) #1st url to return to ur own app, 2nd url for paypal to send notification values = { :business => ‘dhyanb_1326716016_biz@gmail.com’, #account generated by paypal :cmd => ‘cart’, :upload => 1, :return => return_url, :invoice => id, :notify_url => notify_url } line_items.each_with_index do |item, index| values.merge!({ “amount#{index+1}” => item.product.price, “item_name_#{index+1}” => item.product.title, “item_number_#{index+1}” => item.product.id, “quantity_#{index+1}” => item.quantity }) end “https://www.sandbox.paypal.com/cgi-bin/webscr?” + values.to_query end

g> In my show.html.erb,i have placed the checkout button with url to return to:
<?php
= button_to “Checkout”, @cart.paypal_url(products_url,payment_notifications_url)
?>

h> You need to be loged in while simulating this service.

i> After clicking on checkout, this will redirect to paypal site with secure connection. This will look like this:-It contains cart details and form for buyer to log in..

j> On this payment page, one needs to give his buyer account id and password to log in. After logging in it will display other user details too with pay-now option. After paying, the buyer can return to his own store by clicking on the link provided on the page.

Notifications from paypal

a>Notifications sent from paypal can be saved in the database.For that we need to have model with proper fields. i.e- rails g model PaymentNotification params:text status:string transaction_id:string cart_id:integer

My notifications controller(create method) will look like this

def create PaymentNotification.create!(:params => params, :cart_id => params[:invoice], :status => params[:payment_status], :transaction_id => params[:txn_id]) render :nothing => true
end

b>There is no direct of testing this,unless deployed in production but it can be tested in the console using curl command. eg-curl -d “txn_id=9JU83038HS278211W&invoice=1&payment_status=Completed” http://localhost:3000/payment_notifications

c>If this command runs without giving any exceptions,then all is well and values will be stored in the database.

Can start making payment now.

Thanks for reading !!!

Source: Railscarma.com