Posts

Showing posts with the label ROR

Postgres database is not running after OSX crash

Every one might have face the problem that Postgres id not running after OSX is crashed. Every time you try to start the Postgres server it will say : - another server might be running; trying to start server anyway You can follow the below steps to get rid of the problem. Step 1: Open your terminal and run   pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start   It will Say   pg_ctl: another server might be running; trying to start server anyway Step 2:  Check the log $ tail -f /usr/local/var/postgres/server.log It will print something like this FATAL:  lock file "postmaster.pid" already exists HINT:  Is another postmaster (PID 326) running in data directory "/usr/local/var/postgres"? FATAL:  lock file "postmaster.pid" already exists HINT:  Is another postmaster (PID 326) running in data directory "/usr/local/var/postgres"? Step 3: Delete the PID file. $ rm /usr/local/var/postgres/postmaster.pid S

Set up Jruby with apache and passenger in EC2

How to set up jruby with apache and passenger in amazone ec2. Step 1: First install jruby using please check the current version in the   link . And make sure you are installing the bin version of it wget 'http://jruby.org.s3.amazonaws.com/downloads/1.7.4/jruby-bin-1.7.4.tar.gz' Step 2: extract the tar file using tar zxvf jruby-bin-1.7.4.tar.gz Step 3: We need to set come environment variable so that it will be accessible from every other place. export JRUBY_HOME=/home/home_directory_name/jruby-1.7.4 export PATH=$JRUBY_HOME/bin:$PATH And Open the .bashrc file and put the path in their sudo nano ~/.bashrc PATH=$PATH:/home/ubuntu/jruby-1.7.4/bin Step 4: Now to check if jruby is properly installed or not put jruby-v If your system does not have java installed then it will show an error like /home/ubuntu/jruby-1.7.4/bin/jruby: line 395: exec: java: not found Don't worry we will install java to fix this. sudo apt-get install openjdk-7-jdk apt-cache

Set up ruby 2.0 and Rails 4.0.1 in Rackspace

First we need to install ruby Step 1)Install Ruby apt-get -y update apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev cd /tmp wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz tar -xvzf ruby-2.0.0-p247.tar.gz cd ruby-2.0.0-p247/ ./configure --prefix=/usr/local make make install Step 2) Install Rails gem install rails 4.0.1 Step 3) Install passenger gem install passenger Step 4) Install Apache2 apt-get install apache2 Step 5) Install Mysql sudo apt-get install mysql-server mysql-client That's it we are done with the setup.

Active resource in rails

This is a powerful feature of rails to communicate between two models in two different application running in two different server. ActiveResource:Base is the main class for mapping RESTful resources as models in a Rails application. Active Resource objects represent your RESTful resources as manipulatable Ruby objects. To map resources to Ruby objects, Active Resource  only needs a class name that corresponds to the resource name (e.g., the class User maps to the resources Products, very similarly to Active Record) and a site value, which holds the URI of the resources. class User < ActiveResource::Base   self.site = "http://api.products.com:3000/" end In order to access products.com controller you need to send the json response like i am going to call the index action so we need to write :- def index @products = Product.all respond_to do |format| format.json { render :json => @products} end end Now the User class is mapped to RESTful resources located

How to write stored procedure in rails 3

Writing Stored procedure in rails 3 Now using Mysql2 gem writing stored procedure is pretty much easy. Just we need to follow the below steps to write  stored procedure in ORM. 1) Connect the database. client = Mysql2::Client.new(:host => "localhost", :username => "root", :database => "XXX", :password => "XYZ", :flags => Mysql2::Client::MULTI_STATEMENTS ) This extra flag option is most important and multiple result sets is normally used when calling stored procedures that return more than one result set. 2) Fetch the data. result  = client.query( 'CALL sp_test'); It will return the Result set. Now result contains first result set and to fetch the Next result set we need to follow the next step While (client.next_result)    result = client.store_result  #To get the next result set end