Open Rails

Open Rails

Monday, December 16, 2013

Install Sublime Text 3 on Ubuntu 13.10

1.  $ sudo add-apt-repository ppa:webupd8team/sublime-text-3

2.  $ sudo apt-get update 

3.  $ sudo apt-get install sublime-text-installer

To disable new version notifications

Go to ( Preferences -> Settings -> User )


Thursday, July 18, 2013

Install Sublime Text-2 on Ubuntu

Open Your terminal type CTRL+alt+t and Type the below commands

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text

sudo sublime-text

To install Sublime Package Control open sublime text and press ctrl + ~ and enter below code

import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if

not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler()));

open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen(''+pf.replace(' ','%20')).read());

print('Please restart Sublime Text to finish installation')

Enjoy Your Sublime with some cool packages.

Tuesday, March 27, 2012

Setup Nginx on server for rails application.

To install nginx you would require passenger first:
install passengar:

$ gem install passenger

$ passenger -v

In order to let Passenger install Nginx, you need to install a dependency first.
$ sudo apt-get install libcurl4-openssl-dev
use rvmsudo than regular sudo to install nginx

$rvmsudo passenger-install-nginx-module
start nginx
$ sudo /opt/nginx/sbin/nginx
$ sudo nano /opt/nginx/conf/nginx.conf (VPS)
$ sudo /etc/init.d/nginx reload (VPS)

configuration file example

server {
listen 80;
root /home/nagendra/test_app/current/public;
passenger_enabled on;

#charset koi8-r;

#access_log logs/host.access.log main;

#location / {
# root html;
# index index.html index.htm;

Friday, March 16, 2012

Steps To Setup Ruby on Rails on ubuntu Server

Log into the server through ssh

ssh default-user@vps-ip-address

for example: root@ip_address

For security purpose never do any operation from root access thats why we should create a user:

#adduser nagendra

#adduser nagendra some-group-name

ex: adduser nagendra admin

Securing your SSH (server) configuration is the next step. Because every Unix system has a “root” user by default, you should disable “root” from logging in using SSH. This makes your system less vulnerable to brute force attacks.

$ nano /etc/ssh/sshd_config

Set PermitRootLogin to no, and reload the SSH configuration so that the changes take effect. Although “root” will be disabled from logging in in future, the current “root” user connection will be maintained.

$ /etc/init.d/ssh reload

Now, log out of your VPS as “root,” and log back in as the new user.

$ logout and $ ssh nagendra@ip_address

Update the server

$ sudo apt-get update 
$ sudo apt-get upgrade 
$ sudo apt-get dist-upgrade 
$ sudo reboot

ssh nagendra@ip-address

We need git and curl setup first

$ sudo apt-get install curl $ sudo apt-get install git-core

Install RVM(stands for Ruby Version Manager and

is “a command line tool that allows you to easily install,

and work with multiple Ruby environments, from interpreters to sets of Gems.)

$ bash < <(curl -s

Navigate to home  
$ cd $ nano .bashrc and add the below line 
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" load the script

$ source .bashrc Verify RVM  
$ type rvm | head -1 the shell should return that “rvm is a function.”
Setting up ruby gems 
$ rvm notes 
$ (sudo apt-get install 
build-essential bison 
openssl libreadline6 libreadline6-dev 
curl git-core zlib1g zlib1g-dev libssl-dev 
libyaml-dev libsqlite3-0 libsqlite3-dev 
sqlite3 libxml2-dev libxslt-dev autoconf 
libc6-dev ncurses-dev ) in one line
$ rvm list known 
$ rvm install 1.9.2 
Set default ruby version 
$ rvm --default use 1.9.2 check  
$ ruby -v 
$ gem -v 
also you can manually update 
$ gem update --system $ gem update 
Install Rails 
$ gem install rails -v 3.0.11(or any version that you need) 
$ rails -v

Monday, February 13, 2012

Installing the postgresql 9.1 on Ubuntu 11

Installation of Postgresql

1. $ sudo add-apt-repository ppa:pitti/postgresql

    1. $ sudo apt-get update and sudo apt-get install postgresql

    2. check if postgresql installed properly

      psql -V //you must get psql (PostgreSQL) 9.0.4

    3. finger postgres to get the installation overview

    4. lets login to postgres

      $su postgres

    5. psql // you would be logged in to psql terminal postgres=# select version();

Setting up root user for postgres

$ su postgres # switch to the user postgres

    $ cd /etc/postgresql/9.0/main     
cp pg_hba.conf         pg_hba.conf.bak.original  
cp postgresql.conf       postgresql.conf.bak.original      
Make changes to pg_hba.config (authetification methods).
host    all         all       trust          
# md5 -> trust
Now we can start our postgres server 
$ sudo /etc/init.d/postgresql restart  
* Restarting PostgreSQL 9.0 database server   
$ sudo /etc/init.d/postgresql status Running clusters: 9.0/main 
Install Pgadmin3 tool for managing postgres
 $ sudo apt-get install pgadmin3   
# install the latest pgAdminIII 
type pgadmin3 in terminal to launch

Sunday, January 15, 2012

Thinking Sphinx for Rails 3

Step 1
Sphinx Installation:

tar -xzf sphinx-0.9.9-rc2.tar.gz
cd sphinx-0.9.9-rc2/
sudo make install

Note: sphinx By default comes with Mysql configuration, to configure it with pgsql
./configure --prefix=/usr/local --with-pgsql --without-mysql

Step 2
Thinking Sphinx Installation

In you Gem File add
1. gem
'thinking-sphinx', :git => '', :require => 'thinking_sphinx'

2. run bundle install

rake thinking_sphinx:index – Create the index
rake thinking_sphinx:reindex – Reindex Sphinx without regenerating the configuration file
rake thinking_sphinx:start – Start up Sphinx's daemon
rake thinking_sphinx:stop – Shut down the daemon

Example Usage of Thinking sphinx
In your Model:
define_index do
indexes location
indexes [first_name, last_name], :as => :name, :sortable => true

let Sphinx know your fields that has to be indexed.

Thats it you can search now using"first_name last_name")

Monday, January 9, 2012

Thumbs up in Rails

1. instal the gem :

gem 'thumbs_up'

.2. Create and run the ThumbsUp migration:

rails generate thumbs_up
rake db:migrate

.3. setting the model that act as voter

class User < ActiveRecord::Base

setting the model that can be voted

class Comment < ActiveRecord::Base

4. To save the Vote
voter.vote_for(voteable) # Adds a +1 vote
voter.vote_against(voteable)    # Adds a -1 vote, vote)
# Adds either a +1 or -1 vote: vote => true (+1), vote => false (-1)

# Removes any previous votes by that particular voter, and votes for.

voter.vote_exclusively_against(voteable) # Removes any previous votes by that particular voter, and votes against.

5. Other Useful methods

positiveVoteCount = voteable.votes_for
negativeVoteCount = voteable.votes_against
plusminus = voteable.plusminus # Votes for minus votes against.

voter.voted_for?(voteable) # True if the voter voted for this object.
voter.vote_count(:up | :down | :all) # returns the count of +1, -1, or all votes

voteable.voted_by?(voter) # True if the voter voted for this object.
voters = voteable.voters_who_voted

Note : ThumbsUp by default only allows one vote per user.

This can be changed by removing:

In vote.rb:

validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id]

In the migration:
add_index :votes, ["voter_id", "voter_type", "voteable_id", "voteable_type"], :unique => true, :name => "uniq_one_vote_only"